pass values between subs

mattahorn

New member
Local time
Today, 06:07
Joined
Feb 28, 2005
Messages
1
Not been doing this too long, but have a question. Have a sub that determines which checkbox(s) are selected. I then want to get the value from that sub and use it in another sub that runs a query to populate listboxes.

Code so far
Public Sub TransportMode()
If Me.checkAir = True Then
strtypes = strtypes & "'Air',"
End If
If Me.checkCar = True Then
strtypes = strtypes & "'Car Hire',"
End If
If Me.checkAll = True Then
strtypes = "'Air','Car Hire',"
End If
strtype = Left(strtypes, Len(strtypes) - 1)
MsgBox strtype
End Sub

Public Sub FromToUpdate()
TransportMode

strSQL = "SELECT DISTINCT MasterTable.From FROM MasterTable WHERE MasterTable.Type IN (" & strtype & ")"
If Len(strbgs) > 0 Then
strSQL = strSQL & " AND MasterTable.BGID IN (" & strbgs & ")"
End If
MsgBox strSQL

How ever when get the message box, the value from first sub is not used by the second. How can I call it across? I'm trying to put bits of code like the first sub into many different sub as they are used again when buttons are pressed on the form etc.

cheers
Matt
 
At the top of your code-screen, you'll see "Option Compare Database".

Below that text, you can declare your variable. Declaring a variable is done like this:

Dim MyVar (As Type)

For example: Dim strtypes As String

The "As String" part isn't nescessary, but it's always better to declare a variable and specifying the data-type it can contain.

Variables that are declared at the top of the code-window can be used in all subs in that module. They will keep their value.

Seth
 

Users who are viewing this thread

Back
Top Bottom