Results 1 to 5 of 5

Thread: Passing values to a Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Location
    Barrie, Ontario - Canada
    Posts
    85

    Passing values to a Form

    Hi Folks,

    I need some help 'passing values' to accomplish this: I want to pass two values to a new form, process the two values, and return to the parent-form with the final values. Can I pass values to a Form_Load event?

    Im fooling around with a module that allows a user to enter data based upon the content of a list contained in a "Drop-Down" combo box.
    ( This control is filled with the State-Names from a table structured with just two fields, "State Name" and "Abbreviation" )
    If a user selects an existing State-Name, everythinhg is fine

    However, if a user enters a State-Name that doesn't exist in the table I will have to make allowances to update the table with two field contents, The New State-Name and the New Abbreviation

    I guess the right way to do that is to call a temporary child-form, but I will need to pass two values to this child-form to manage.
    Lets say that cText will be the new State-Name entered and cAns will be the variable that will accept the New Abbreviation.


    Calls the temporary child:
    frmAddToTable.Show vbModal, Me

    Thyan k you for any help

    -Paul-

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Passing values to a Form

    You cannot pass values to the Form_Load event. Two options

    1) Create two new Properties for the Form and set them before calling the Show Method.
    2) Create your own Initialize function in frmAddToTable, passing the two arguments.

    VB Code:
    1. 'in frmAddToTable
    2. Public Function Initialize(Byval StateName as string ,Byval StateAbbrev as String)
    3.    'code to initialize form
    4.    Me.Show vbModal
    5.    'clean up code
    6. End Function
    7.  
    8. 'other Forms
    9. frmAddToTable.Initialize cText, cAns

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Passing values to a Form

    I dont know why you would need two forms for this. Put a command button on the form with its Enabled property set to False. Put two textboxes on the form, one called txtNewState and one called txtNewStateAbbrv.

    In the change event for the new state textbox put
    VB Code:
    1. Private Sub txtNewState_Change()
    2. If Len(txtNewState) > 0 Then
    3.    cmdUpdate.Enabled = True
    4. Else
    5.    cmdUpdate.Enabled = False
    6. End If
    7. End Sub

    In the command button, put something like
    VB Code:
    1. Private Sub cmdUpdate_Click()
    2. Dim sSQL As String
    3. sSQL = "INSERT INTO tablename (state, state_abbrv) VALUES ('" & txtNewState.Text & "', '" & txtNewStateAbbrv.Text & "')"
    4. 'execute in the insert query
    5. cmdUpdate.Enabled = False
    6. txtNewState.Text = vbNullString
    7. txtNewStateAbbrv.Text = vbNullString
    8. End Sub
    And there you have it.

  4. #4
    Lively Member mowafy's Avatar
    Join Date
    Jul 2005
    Posts
    116

    Re: Passing values to a Form

    declear 2 public variable on a module and you can read it from any where

  5. #5
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: Passing values to a Form

    declear the variables on a module and u will b able to use them from everywhere have fun

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