Help with WHERE statement to filter report contents.

G

Guest

What am I doing wrong? I need to filter the contents of a the "Recycled
Interface Report". I am using a combo box named("Field") to select the field
that should be used to filter. I am then using a text box("Search
Information") as the parameter that must be present in the "Field" field of
the data table to show up in the report. I know this must be a syntax
problem. This WHERE statement works fine( 'strWhere = "[Serial Number]='" &
Me![Serial Number] & "'"
) when the search field is fixed as "Serial Number" but when I want to use
the value of the "field" control in the Sub below it errors.


Private Sub Search_Button_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "Recycled Interface Report"
strWhere = "Me!Field.Value='" & Me![Search Information] & "'"
DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

Any suggestions? Thanks in advance.
 
G

Guest

"Field" is not a good name for a field or control or anything else. Change
the combo box name to cboField and try something like:
strWhere = "[" & Me!cboField & "] ='" & Me![Search Information] & "'"
 
G

Guest

That was it! Thank you. And yes, I will be more concious of how I name my
controls. I have good habits for naming variables but I never thought to
apply the same principles to naming controls and other objects.
--
Regards, Michael


Duane Hookom said:
"Field" is not a good name for a field or control or anything else. Change
the combo box name to cboField and try something like:
strWhere = "[" & Me!cboField & "] ='" & Me![Search Information] & "'"
--
Duane Hookom
Microsoft Access MVP


Mac said:
What am I doing wrong? I need to filter the contents of a the "Recycled
Interface Report". I am using a combo box named("Field") to select the field
that should be used to filter. I am then using a text box("Search
Information") as the parameter that must be present in the "Field" field of
the data table to show up in the report. I know this must be a syntax
problem. This WHERE statement works fine( 'strWhere = "[Serial Number]='" &
Me![Serial Number] & "'"
) when the search field is fixed as "Serial Number" but when I want to use
the value of the "field" control in the Sub below it errors.


Private Sub Search_Button_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "Recycled Interface Report"
strWhere = "Me!Field.Value='" & Me![Search Information] & "'"
DoCmd.OpenReport strDocName, acPreview, , strWhere
End Sub

Any suggestions? Thanks in advance.
 

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