Passing variables to forms

wchernock

Registered User.
Local time
Today, 11:17
Joined
Jun 18, 2007
Messages
28
I am trying to pass the following variables between multiple forms

CurrentForm
PreviosForm
NextForm
ProjectID

The intent is to simplify the code for my Back button, and "Open next Form" button. The next form typically is opened with a where projectID = projectID from current form.

I have tried to list the variable in the public section of my first form but that does not seem to work.

Mainly the form variables are to track navigation through the application screens.

Thoughts, suggestions, examples???


Below is the code from one of my forms:

Private Sub cmd_BackToProjectList_Click()
On Error GoTo Err_cmd_BackToProjectList_Click

Dim stLinkCriteria As String

stLinkCriteria = "[ProjectID]=" & "'" & Me![ProjectID] & "'"

DoCmd.Close acForm, CurrentForm, acSaveNo

DoCmd.OpenForm PreviousForm, , , stLinkCriteria
CurrentForm = PreviousForm

Exit_cmd_BackToProjectList_Click:
Exit Sub

Err_cmd_BackToProjectList_Click:
MsgBox Err.Description
Resume Exit_cmd_BackToProjectList_Click

End Sub

Private Sub cmd_GoToDeliverables_Click()
On Error GoTo Err_cmd_GoToDeliverables_Click

Dim stLinkCriteria As String

NextForm = "Frm-ProjectDeliverableList"

stLinkCriteria = "[ProjectID]=" & "'" & Me![ProjectID] & "'"

DoCmd.Close acForm, CurrentForm, acSaveNo
PreviousForm = CurrentForm

DoCmd.OpenForm NextForm, , , stLinkCriteria
CurrentForm = NextForm

Exit_cmd_GoToDeliverables_Click:
Exit Sub

Err_cmd_GoToDeliverables_Click:
MsgBox Err.Description
Resume Exit_cmd_GoToDeliverables_Click

End Sub
 
With your scheme, put your Public Variables in a standard module and they will be available to all of your forms.
 
How do I create a standard module? How or where do I call it or use it?

When the DB open I have a Login Form that passes me into the application (moving through various forms linked by cmd buttons in a tree like fashion)
 
From the left side of the database window select the module and then new. Post back if you need further assistance.
 
From the left side of the database window select the module and then new. Post back if you need further assistance.

Can I have a standard module with just public variable declarations and default valus? How do I call it to make sure it is executed?
 
You don't call variables, you assign values to them and read their values. By placing them in the standard module general declarations section and declaring them as Public you make their scope the entire project so you can assign and read their values from anywhere in your project.
 
You don't call variables, you assign values to them and read their values. By placing them in the standard module general declarations section and declaring them as Public you make their scope the entire project so you can assign and read their values from anywhere in your project.



My question is how do I ensure the standard module is executed so that the variables get declared for use in the forms?
 
You don't need to. When you declare them in your standard module (not within a sub or a function (can be from a form module or standard module for that), but within the declarations section) they are ready when you start. If you want them to have initial values you will have to run some sub or function to assign them their values.
 

Users who are viewing this thread

Back
Top Bottom