Why Can't I Assign This Value?

saross

Registered User.
Local time
Today, 06:19
Joined
Mar 4, 2003
Messages
120
I'm having trouble assigning a value to a long variable using a text box on a form. Here's the code:

Dim strSQL As String
Dim strOpenForm As String
Dim strCloseForm As String
Dim lngContactID As Long

lngContactID = Me.SelectedContactID.Value
strOpenForm = "FrmContact"
strCloseForm = "FrmContactsByInterest"
strSQL = "ContactID = lngContactID"

DoCmd.OpenForm strOpenForm, , , strSQL
DoCmd.Close acForm, strCloseForm

I get a message box asking for lngContactID when I run it. Can anyone tell me why?
 
It's OK, I Found Out What Was Wrong

Changed line to:

strSQL = "ContactID = " & lngContactID & ""

Thanks anyway!
:rolleyes:
 
Your line assigning the value to strSQL is not actually using your variable lngContactID, rather it is setting a where clause of
ContactID = lngContactID.

You need to set the strSQL as follows:

strSQL = "ContactID =" & lngContactID

This will then use the actual value in the variable lngContactID.
 

Users who are viewing this thread

Back
Top Bottom