Syntax for Autonumber + Where Condition

  • Thread starter Thread starter Melissa
  • Start date Start date
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.
 
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
 
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 &""""
 
Back
Top