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 &""""
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Where Condition & Quotation Marks 3
Syntax error 2
Syntax for opening a form with condition 2
Urgent Help is Needed Please 2
Append query with multiple joins 1
Macro to VB 5
Event Procedure 2
Correct Syntax 8

Back
Top