Simple Report Question

A

Andrew Hollis

How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 
K

Klatuu

Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
 
A

Andrew Hollis

Using the code in the OK buttons on click box only yielded an empty report.
Heres what I put in:
Private Sub OK_Click()
Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[Description] = """ & Me.MyTextBox & """"
End If
DoCmd.OpenReport "rptKeyWord", acViewPreview, , strWhere
End Sub


Klatuu said:
Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 
A

Andrew Hollis

^^ works ok when the box is empty, but will only yield a empty report for any
keywords that I try.

Andrew Hollis said:
Using the code in the OK buttons on click box only yielded an empty report.
Heres what I put in:
Private Sub OK_Click()
Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[Description] = """ & Me.MyTextBox & """"
End If
DoCmd.OpenReport "rptKeyWord", acViewPreview, , strWhere
End Sub


Klatuu said:
Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 
K

Klatuu

My bad, I think what you are wanting to do is find a specific word somewhere
in the description field. If this is correct, then you need to change this
line:
strWhere = "[Description] = """ & Me.MyTextBox & """"
To:
strWhere = = "[Description] Like ""*" & Me.MyTextBox & "*"""

Now, Me.MyTextBox was a made up name. Be sure you are referring to the text
box name on your form.
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
Using the code in the OK buttons on click box only yielded an empty report.
Heres what I put in:
Private Sub OK_Click()
Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[Description] = """ & Me.MyTextBox & """"
End If
DoCmd.OpenReport "rptKeyWord", acViewPreview, , strWhere
End Sub


Klatuu said:
Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 
A

Andrew Hollis

Perfect except there is a double equals (==) in the expression. It works ok
with just one equals, so I'm assuming a typo.

Thanks!

Klatuu said:
My bad, I think what you are wanting to do is find a specific word somewhere
in the description field. If this is correct, then you need to change this
line:
strWhere = "[Description] = """ & Me.MyTextBox & """"
To:
strWhere = = "[Description] Like ""*" & Me.MyTextBox & "*"""

Now, Me.MyTextBox was a made up name. Be sure you are referring to the text
box name on your form.
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
Using the code in the OK buttons on click box only yielded an empty report.
Heres what I put in:
Private Sub OK_Click()
Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[Description] = """ & Me.MyTextBox & """"
End If
DoCmd.OpenReport "rptKeyWord", acViewPreview, , strWhere
End Sub


Klatuu said:
Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
--
Dave Hargis, Microsoft Access MVP


:

How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 
K

Klatuu

It was indeed a typo. Glad you got it working.
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
Perfect except there is a double equals (==) in the expression. It works ok
with just one equals, so I'm assuming a typo.

Thanks!

Klatuu said:
My bad, I think what you are wanting to do is find a specific word somewhere
in the description field. If this is correct, then you need to change this
line:
strWhere = "[Description] = """ & Me.MyTextBox & """"
To:
strWhere = = "[Description] Like ""*" & Me.MyTextBox & "*"""

Now, Me.MyTextBox was a made up name. Be sure you are referring to the text
box name on your form.
--
Dave Hargis, Microsoft Access MVP


Andrew Hollis said:
Using the code in the OK buttons on click box only yielded an empty report.
Heres what I put in:
Private Sub OK_Click()
Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[Description] = """ & Me.MyTextBox & """"
End If
DoCmd.OpenReport "rptKeyWord", acViewPreview, , strWhere
End Sub


:

Use the Where argument of the OpenReport method to filter your report's
record source based on the value of the text box. You will be using the text
box to search on a specific field. Then use the Click event of the Ok button
to build the filtering string and open the report:

Dim strWhere As String

If Not IsNull(Me.MyTextBox) Then
strWhere = "[FieldToSearch] = """ & Me.MyTextBox & """"
End IF
Docmd.OpenReport "MyReportName", acViewPreview, , strWhere

Note, the above code assumes FieldToSearch is a text field. Use the actual
names of your field and text box. If you want all records in the report,
just leave the text box empty
--
Dave Hargis, Microsoft Access MVP


:

How do I create a Form that will search my database for a keyword and
populate a report with the results.

I made a report that has all the records in it. I'd like for the form
(which would contain a text box, ok, and cancel button) to abbreviate the
form into only entries that contain the keyword that the user supplies.
 

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