DoCmd.OpenReport Where Clause (1 Viewer)

DoubleD

New member
Local time
Yesterday, 21:59
Joined
May 27, 2009
Messages
2
I'm having a problem using VBA to open a report. My code uses a passed OpenArg variable to select records but it isn't working. My code is:

DoCmd.OpenReport DocName, acViewPreview, , "tblcustcall.[ExaminerID]= Arg2", acWindowNormal

No matter how I format the string the variable Arg2 is not assigned to the field [ExaminerID]. The debugger shows the correct value for Arg2. If I change Arg2 to the text DDOS2 the report is properly filtered.:mad: Anyhelp on the formatting would be appreciated.
 

SOS

Registered Lunatic
Local time
Yesterday, 21:59
Joined
Aug 27, 2008
Messages
3,517
DoCmd.OpenReport DocName, acViewPreview, , "[ExaminerID]='" & Arg2 & "'"
 

DoubleD

New member
Local time
Yesterday, 21:59
Joined
May 27, 2009
Messages
2
Thanks you are correct. Any explanation on the formatting? I've gone nuts trying to figure out the format. :)
 

SOS

Registered Lunatic
Local time
Yesterday, 21:59
Joined
Aug 27, 2008
Messages
3,517
Thanks you are correct. Any explanation on the formatting? I've gone nuts trying to figure out the format. :)
When you are looking for values from

1. A Text Field - surround with quotes (single quotes, triple double quotes or Chr(34) will do).
DoCmd.OpenReport DocName, acViewPreview, , "[ExaminerID]='" & Arg2 & "'"
OR
DoCmd.OpenReport DocName, acViewPreview, , "[ExaminerID]=" & """ & Arg2 & """
OR
DoCmd.OpenReport DocName, acViewPreview, , "[ExaminerID]=" Chr(34) & Arg2 & Chr(34)

2. A Date Field - Surround with octothorpes (#)
DoCmd.OpenReport DocName, acViewPreview, , "[DateFieldName]=#" & Arg2 & "#"

3. A numeric Field - do not use anything.
DoCmd.OpenReport DocName, acViewPreview, , "[NumericFieldName]=" & Arg2
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top Bottom