Passing Variable between Forms

Abbos

Registered User.
Local time
Today, 19:18
Joined
May 11, 2005
Messages
64
Hi Everyone,

I'm trying to pass a variable called MyFilter between forms but am having problems. I have created a Module and declared MyFilter as a public string.

The original code in my first form is:

Code:
Private Sub Command65_Click()
Dim MyFilter As String
If Me.Filter = "" Then
        MsgBox "Please apply a filter to the form first."
ElseIf Me.Dirty Then
' Make sure the record is saved
RunCommand acCmdSaveRecord
Else
    MyFilter = Me.Filter
    DoCmd.OpenReport "Temp", acViewPreview, , MyFilter
    
End If
End Sub

How to I change this so that it now stores the value in the Public variable instead of the Private one which it is doing above?

Thanks,
 
Declare the variable in a module.

Public MyFilter As String
 
Abbos said:
I have created a Module and declared MyFilter as a public string.

Hi Oldsoftboss,

I have done this already. The issue I have is how do I change my original code so that it now stores the value in the Public variable instead of the Private one which it is currently doing (see first post above for code).
 
Oldsoftboss said:
Declare the variable in a module.

Declare it in a public module, not a form module. In the database window, select modules and then new.

Add:

Public MyFilter As String

and save the module. It doesn't matter if this is the only thing in the module.

Dave
 
I had done that part right. I found that the issue was in my code which was calling the public variable. Thanks.
 

Users who are viewing this thread

Back
Top Bottom