|
-
Jul 26th, 2005, 09:53 AM
#1
Thread Starter
Lively Member
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-
-
Jul 26th, 2005, 10:09 AM
#2
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:
'in frmAddToTable
Public Function Initialize(Byval StateName as string ,Byval StateAbbrev as String)
'code to initialize form
Me.Show vbModal
'clean up code
End Function
'other Forms
frmAddToTable.Initialize cText, cAns
-
Jul 26th, 2005, 10:15 AM
#3
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:
Private Sub txtNewState_Change()
If Len(txtNewState) > 0 Then
cmdUpdate.Enabled = True
Else
cmdUpdate.Enabled = False
End If
End Sub
In the command button, put something like
VB Code:
Private Sub cmdUpdate_Click()
Dim sSQL As String
sSQL = "INSERT INTO tablename (state, state_abbrv) VALUES ('" & txtNewState.Text & "', '" & txtNewStateAbbrv.Text & "')"
'execute in the insert query
cmdUpdate.Enabled = False
txtNewState.Text = vbNullString
txtNewStateAbbrv.Text = vbNullString
End Sub
And there you have it.
-
Jul 26th, 2005, 11:05 AM
#4
Lively Member
Re: Passing values to a Form
declear 2 public variable on a module and you can read it from any where
-
Jul 26th, 2005, 01:14 PM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|