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

Use Local Variables in GLobal Module. 1

Status
Not open for further replies.

DerickD

IS-IT--Management
Sep 19, 2002
93
LU
Hi All,

The problem is very simple to explain but sounds stupid, but if I can do this then I can do what I want (which is slighlty more complicated and Harder to explain) :

Say I have, 100 forms. Each form is the same but with diffrent names.

Each form contains a text box, a Dropdown box and a button.

Text box1 : Type in message "Bill lives here".
Dropdown1 : Select one of the 100 forms names.
Button : When pressed, displays the messaage "Bill Lives Here" and then goes to the form that you selected in the dropdown.


I want to put the same "Global" sub on each of the 100 buttons, and have the information in the text box and dropdown sent to the Global sub as parameters.

This is how I would imagine it be like :

--------------------------------------------
Private Sub MsgAndMove_btn()

'Set up Variables
Dim Var1
Dim Var2
Var1 = me![MessageBox_Text]
Var2 = me![Form_DropDown]

'Call Global Procedure
Msg_And_Text ,Var1 ,Var2

End Sub
--------------------------------------------

Then the Global module would then use Var1 and Var2 to :

--------------------------------------------
Sub Msg_And_Text

msgbox(Var1)
openform Var2...blah...blah

End Sub
--------------------------------------------

Thanks alot for even reading this far....
DerickD
 
From a design point of view, why not use one form and change the data behind it? But as you said, it is more complex than is worth going into, so I'll take it on faith that indeed you need 100 different forms.
You could use a text box for your message, but how about making your combo box two columns wide and put your text in there? Also you didn't mention closing the previous form, but I figured you would want to.

Private Sub cboForm_AfterUpdate()
NextForm cboForm.Column(0), cboForm.Column(1), Me.Name
End Sub

Function NextForm(FormName As String, MsgTxt As String, OldFormName As String)
MsgBox MsgTxt
DoCmd.Close acForm, OldFormName
DoCmd.OpenForm FormName
End Function
HTH
NorthNone
 
Hi thanks for the reply...But what you have written seems to only be a 'Private Sub'. I want to use the Private sub to just set the variables and thats it. I then want the variables to be passed to a 'common' or 'Public' or 'Global' Procedure that would then use the two variables to peform the action required.

I hope I make scence...

Thanks
DerickD
 
No no no no....Igonore my last reply it seems to be OK...


Thanks
 
Glad you took a second look, Derick and decided it was OK. To be honest, I put a fair amount of time into this and went above and beyond what you originally asked for, delivering compact code, ready to use. In addition, I incorporated code that closed the form you were leaving. Better than "OK", perhaps a star?
 
Hey NorthNone,

Wow...your correct I used it and it worked perfectly, I think that if any one uses your code, they should instantly award you with a star, and tell there friend to use the code...etc...

There's one from me, and I will tell my friends.... :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top