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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access VBA: How to pass variables from one class procedure to another?

Status
Not open for further replies.

Spruce4U

Technical User
Feb 1, 2006
23
CA
How can we pass any variable from a class procedure to another?

For example, when the user selects a value from a combo list in a form, a second form pops up and asks a question.

1. I want the value selected in the first form to be written on top of the second form (as a title).

2. I want the answer selected in the second form to be put on the first.

Can anyone help?

Thanks a lot.
 
How about just referencing the form? For example:
Code:
Private Sub Form_Open(Cancel As Integer)
Me.Caption = Forms!frmForm!cboCombo
End Sub

Something similar can be done on the After Update event of what ever textbox is being changed:
[tt]Forms!frmForm!txtText = Me.txtOtherText[/tt]
 
How are ya Spruce4U . . .

Have a look at the last arguement of the DoCmd.OpenForm method . . . [purple]OpenArgs![/purple]

If necesary you can [blue]concatenate multiple values together[/blue] and break them apart in the opened form with the [purple]Split[/purple] function . . .

[blue]Your thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .
 
Thanks Remou.

However, the first form is in datasheet view, and when in the second form, specifying Forms!frmfrom!txtText to reach the first one won't do because there are many records listed instead of one as in a single form view.

In addition, the second form is in acDialog mode, which complicates things a bit since no more code is executed before the form is closed.

I partly solved the problem by storing in a tablle the values I want to pass from one form to the other, but there must be a simpler way to do it!

Do you have any more clues about how to pass a variable from the class module of form 1 to the class module of form2???


Thanks!


 
Hi!

Take another look at AceMan's suggestion.

DoCmd.OpenForm "YourForm", , , , , acDialog, YourVariableAsAString

Then, in the second form's module.

Me.OpenArgs

will retrieve the variable as a string.

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
Great thanks AceMan, Remou and Jebry, I'm trying your suggestions right now.

Thanks again for replying so fast.

 
Ok, now it works perfectly for passing data (via OpenArgs) from the first to the second form, thanks.

Now, what about passing info from the second form to the first? I succeeded in doing it by storing data in a table to which is linked my 2nd form and getting it back with DLookup in my 1st form, but how to do it in a simpler way?

Is seems quite difficult to have 2 class modules communicating variables together...
 
Provided the 2 forms are open:
Forms!Form1!Somecontrol = Forms!Form2!Anothercontrol

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top