docmd.openreport where clause syntax

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