Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing VAR between forms 2

Status
Not open for further replies.
Oct 1, 2003
53
US
I have a form where the user selects a company name from a drop down list.

I would like to have the user click a button then opening another form with the information about the user's selected company prepopulted.

How do i read the selection into a VAR and then pass the VAR to the next form?
 
This has been addressed many times in this forum. Try doing a keyword search.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Hi

You can pass values from form to form using .OpenArgs (see help for exact syntax, examples etc)

If both forms are open, you can also address the controls of one form from another using the Forms!MyFormName!MyControlName type Syntax

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
i have the var being read into a string the problem seems to be on the 2nd form where i want to read the var being passed into a new var. here is the code i am using:

Private Sub Form_Load()

Dim stCompName2 As String

stCompName2 = Me.OpenArgs

End Sub
 
here also is the code i am using on form1 to read the var into the string and pass it using openargs
 
Private Sub var_passing_button_Click()
On Error GoTo Err_var_passing_button_Click

Dim stDocName As String
Dim stCompName As String

stCompName = Trim(Me.List1)
stDocName = "a_test_var_passin_Form2"
DoCmd.OpenForm stDocName, , , stCompName
 
Hi

You need your code in the form open event

Private Sub Form_Open()

Dim stCompName2 As String

stCompName2 = Me.OpenArgs

End Sub

also if you want stCompName2 to be available globally within the form you need to dim it in the GEneral section, the way you have dimmed it, it is local to the Open event (or Load event as you had it)

Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
its telling me invalid use of null which tells me that i am either not getting the var over there or i am not reading it in correctly.
 
i have the following code in my open event in the second form:

Private Sub Form_Open(Cancel As Integer)



stCompName2 = Me.OpenArgs



End Sub
 
I think the problem is in your OpenForm statement. You don't have the correct number of arguments. The data to be passed to the second form which can be accessed by the OpenArgs method is the 6th argument. You have it as the 4th arguement.

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
thanks to both of you i have the var passing with no more error, one last question how do i prove i am passing what i think i am...please be merciful for i am a network guy not an access code guy....

(perhaps a msgbox?)
 
Do you for debugging purposes or do you meanfor programatic validation?

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
when the second form loads i would like to see a msgbox with the var i passed so that i know i am indeed passing what i think i am...
 
Add the following line to KenReay's code posted above:
Code:
Private Sub Form_Open()
   
   Dim stCompName2 As String
   
   stCompName2 = Me.OpenArgs[COLOR=blue]
   MsgBox stCompName2[/color]

End Sub

Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top