Results 1 to 3 of 3

Thread: Saving Filled in Form Files Onto blank Forms.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    12

    Saving Filled in Form Files Onto blank Forms.

    Hi, What im trying to do is click a command button and have all of the text on the form that has the command button get saved onto another form that looks just like it but is blank with no text.
    This is what i have for the save click event so far:

    Private Sub cmdSave_Click()
    Dim Filenum As Integer
    On Error GoTo ErrHandler
    Filenum = FreeFile
    dlgFile.Filter = "all files(*.*)|*.*|Form Files(*.frm)|*.frm"
    dlgFile.FilterIndex = 2
    dlgFile.ShowSave
    strTheFileName = dlgFile.FileName
    Open strTheFileName For Output As #Filenum
    Print #Filenum, lstPolicy.Text
    Close #Filenum
    blnSaved = True
    Exit Sub
    ErrHandler:
    Exit Sub
    End Sub

    With this code i get a save screen to pop up but when i try to save it nothing happens no information is saved onto a form. Can anyone help me? Does this make any sense at all?

    -Flaw

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    If you're just trying to copy values from one form to another then there are a number of ways you could do it.

    One method, (if the controls on the 2nd form have the same name as the ones on the main form), would be to cycle through the controls on the Form and check to see if they exist on the 2nd, if so, populate them with the values on this form, i.e.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Command1_Click()
    4.     Dim objControl As Control
    5.    
    6.     Load Form2
    7.    
    8.     For Each objControl In Controls
    9.         If TypeOf objControl Is TextBox Then
    10.             If HasControl(objControl.Name, Form2) Then
    11.                 Form2.Controls(objControl.Name).Text = objControl.Text
    12.             End If
    13.         End If
    14.     Next
    15.    
    16.     Form2.Show vbModal, Me
    17. End Sub
    18.  
    19. Private Function HasControl(ByVal sName As String, ByRef Parent As Form) As Boolean
    20.     On Error GoTo NoControl
    21.    
    22.     HasControl = Parent.Controls(sName).Name = sName
    23.    
    24. NoControl:
    25.     On Error GoTo 0
    26. End Function

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2002
    Posts
    12
    Hey thx Aaron for the code, I used it to transfer textbox and label information from my first form to the other one but i cant get it to transfer ListBox information. The property .text didnt work for the ListBox just for the textbox.

    For Each objControl2 In Controls
    If TypeOf objControl2 Is ListBox Then
    If HasControl(objControl2.Name, Form2) Then
    Form2.Controls(objControl2.Name).Text = objControl2.Text
    End If
    End If
    Next

    Form2.Show vbModal, Me
    End Sub

    This code doesnt work to transfer the ListBox information over to the form. I dont know, what property or method to use in place of .text for a ListBox?

    thx again

    -Flaw

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width