expression error

X

xg

I want to preview a report from a form which display current record. My
conditions are: either current stID, or stID is blank

However, my report only shows current stID, but not records with stID is
blank. Where did I do wrong?

Private Sub cmdPreviewCourse_Click()
On Error GoTo Err_cmdPreviewCourse_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "rptMyProgram"

' This line is the problem
strWhere = "[stID]=""" & Me!stID & """ or [stID]= ""Is Null"""

DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_cmdPreviewCourse_Click:
Exit Sub

Err_cmdPreviewCourse_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewCourse_Click

End Sub
 
A

Allen Browne

If you want to return the records where the field matches or is null:
strWhere = "(stID Is Null) OR ([stID]=""" & Me!stID & """)"

If you want to show all records when stID is left blank, test for IsNull(),
and omit the condition:
If Not IsNull(Me.stID) Then
strWhere = "[stID]=""" & Me!stID & """"
End If
 
X

xg

Works great! Thanks a lot.

Allen Browne said:
If you want to return the records where the field matches or is null:
strWhere = "(stID Is Null) OR ([stID]=""" & Me!stID & """)"

If you want to show all records when stID is left blank, test for
IsNull(), and omit the condition:
If Not IsNull(Me.stID) Then
strWhere = "[stID]=""" & Me!stID & """"
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

xg said:
I want to preview a report from a form which display current record. My
conditions are: either current stID, or stID is blank

However, my report only shows current stID, but not records with stID is
blank. Where did I do wrong?

Private Sub cmdPreviewCourse_Click()
On Error GoTo Err_cmdPreviewCourse_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "rptMyProgram"

' This line is the problem
strWhere = "[stID]=""" & Me!stID & """ or [stID]= ""Is Null"""

DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_cmdPreviewCourse_Click:
Exit Sub

Err_cmdPreviewCourse_Click:
MsgBox Err.Description
Resume Exit_cmdPreviewCourse_Click
End Sub
 

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