Syntax for Autonumber + Where Condition

M

Melissa

Please help if you can. I have the most difficult time with correct syntax
in the WHERE conditions. Could someone please let me know what I did wrong
in the following code?

Dim lngCriteria1 as Long
lngCriteria1 = "AttachmentID = & Me.AttachmentID &"

If Me.OptionGroup = 1 Then
DoCmd.OpenForm FormName:="frmattachmentssub", WhereCondition:=lngCriteria1

AttachmentID is an autonumber field that is also the PK. I appreciate any
help.
 
D

Douglas J. Steele

In addition to what Jack said, the Where condition needs to be a string, not
a Long Integer.

Dim strCriteria1 as String

strCriteria1 = "AttachmentID = " & Me.AttachmentID

If Me.OptionGroup = 1 Then
DoCmd.OpenForm FormName:="frmattachmentssub",
WhereCondition:=strCriteria1
 
M

Marshall Barton

Melissa said:
Please help if you can. I have the most difficult time with correct syntax
in the WHERE conditions. Could someone please let me know what I did wrong
in the following code?

Dim lngCriteria1 as Long
lngCriteria1 = "AttachmentID = & Me.AttachmentID &"

If Me.OptionGroup = 1 Then
DoCmd.OpenForm FormName:="frmattachmentssub", WhereCondition:=lngCriteria1

AttachmentID is an autonumber field that is also the PK. I appreciate any
help.


For number type fields, use:

lngCriteria1 = "AttachmentID =" & Me.AttachmentID

For Text fields, the quoting could be:

lngCriteria1 = "AttachmentID =""" & Me.AttachmentID &""""
 
Top