docmd.openreport where clause syntax

G

Guest

can someone tell me what's wrong with this where clause?

Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String

stDocName = "Audit Reports"
DoCmd.OpenReport stDocName, acNormal, , "[IRB Number] = " & Forms![Audit
Report]![IRB Number]

Exit_PrintReport_Click:
Exit Sub

Err_PrintReport_Click:
MsgBox Err.description
Resume Exit_PrintReport_Click

End Sub
 
J

John Conklin

Ted,

You need to add the words wherecondition like the example below:

DoCmd.OpenReport ReportName:="RPT - Issue Audit Report - By Individual
(Ana)", _
View:=acViewPreview, _
wherecondition:="[Assigned To] = '" & Me.lstEmployee &
"'"

Hope that helps,

~John
 
T

Tim Ferguson

can someone tell me what's wrong with this where clause?
DoCmd.OpenReport stDocName, acNormal, , _
"[IRB Number] = " & Forms![Audit Report]![IRB Number]


Not without some more information:-

What error or occurrence are you seeing?

Is the form open?
Does stDocname report definitely exist?
Is there any value in the control?
Is it a valid number?
Is it a recognised IRB Number?


B Wishes


Tim F
 
F

fredg

can someone tell me what's wrong with this where clause?

Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String

stDocName = "Audit Reports"
DoCmd.OpenReport stDocName, acNormal, , "[IRB Number] = " & Forms![Audit
Report]![IRB Number]

Exit_PrintReport_Click:
Exit Sub

Err_PrintReport_Click:
MsgBox Err.description
Resume Exit_PrintReport_Click

End Sub

Your syntax looks ok IF..... [IRB Number] is a Number datatype.

If it is text datatype, then use:
"[IRB Number] = '" & Forms![Audit Report]![IRB Number] & "'"

And if this code is actually on the "Audit Report" form, use the Me
keyword:
"[IRB Number] = '" & Me![IRB Number] & "'"
 
M

Marshall Barton

Ted said:
can someone tell me what's wrong with this where clause?

Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String

stDocName = "Audit Reports"
DoCmd.OpenReport stDocName, acNormal, , "[IRB Number] = " & Forms![Audit
Report]![IRB Number]


It's missing a comma.
 
F

fredg

Ted said:
can someone tell me what's wrong with this where clause?

Private Sub PrintReport_Click()
On Error GoTo Err_PrintReport_Click

Dim stDocName As String

stDocName = "Audit Reports"
DoCmd.OpenReport stDocName, acNormal, , "[IRB Number] = " & Forms![Audit
Report]![IRB Number]

It's missing a comma.

Where, Marsh? I count 3.
 

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

Top