Search Filter for Report

M

Mr-Re Man

I have used some code from this discussion group to filter a report. The
form I have created has two fields, 1 unbound combo box (cboTeams) and 1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input a date
and then click the button 'Create Report' and it displays the filtered data
only.

So far, I have only been able to find code that relates to a combo box.

I would be gratefule if somebody would be able to spare a few minutes to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is left blank
as the database holds about 20,000 records. By selecting an individual day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub

tia
 
A

Allen Browne

Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive example,
offering the user lots of things to filter by (combos, text boxes, numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , strWhere
 
M

Mr-Re Man

Thanks for the quick response. I have downloaded your examples previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I have
tried to all morning to work your code into mine, making tweaks here and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is appreciated.

Allen Browne said:
Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive example,
offering the user lots of things to filter by (combos, text boxes, numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , strWhere

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

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

Mr-Re Man said:
I have used some code from this discussion group to filter a report. The
form I have created has two fields, 1 unbound combo box (cboTeams) and 1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input a date
and then click the button 'Create Report' and it displays the filtered
data
only.

So far, I have only been able to find code that relates to a combo box.

I would be gratefule if somebody would be able to spare a few minutes to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is left
blank
as the database holds about 20,000 records. By selecting an individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub

tia
 
A

Allen Browne

You said you wanted a message box if there was not date. Here's that part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate, "\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Mr-Re Man said:
Thanks for the quick response. I have downloaded your examples previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I have
tried to all morning to work your code into mine, making tweaks here and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

Allen Browne said:
Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , strWhere

Mr-Re Man said:
I have used some code from this discussion group to filter a report.
The
form I have created has two fields, 1 unbound combo box (cboTeams) and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input a
date
and then click the button 'Create Report' and it displays the filtered
data
only.

So far, I have only been able to find code that relates to a combo box.

I would be gratefule if somebody would be able to spare a few minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is left
blank
as the database holds about 20,000 records. By selecting an individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
M

Mr-Re Man

Thanks Allan, I have used that code and it works fine, but how do I filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

Allen Browne said:
You said you wanted a message box if there was not date. Here's that part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate, "\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Mr-Re Man said:
Thanks for the quick response. I have downloaded your examples previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I have
tried to all morning to work your code into mine, making tweaks here and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

Allen Browne said:
Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , strWhere

I have used some code from this discussion group to filter a report.
The
form I have created has two fields, 1 unbound combo box (cboTeams) and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input a
date
and then click the button 'Create Report' and it displays the filtered
data
only.

So far, I have only been able to find code that relates to a combo box.

I would be gratefule if somebody would be able to spare a few minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is left
blank
as the database holds about 20,000 records. By selecting an individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
A

Allen Browne

After the date, and before the OpenReport:

If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If

That assumes Team is a Text field.
Lose the extra quotes if it is a Number field.

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

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

Mr-Re Man said:
Thanks Allan, I have used that code and it works fine, but how do I filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

Allen Browne said:
You said you wanted a message box if there was not date. Here's that
part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate,
"\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Mr-Re Man said:
Thanks for the quick response. I have downloaded your examples
previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I
have
tried to all morning to work your code into mine, making tweaks here
and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide
the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

:

Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive
example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
strWhere

I have used some code from this discussion group to filter a report.
The
form I have created has two fields, 1 unbound combo box (cboTeams)
and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input
a
date
and then click the button 'Create Report' and it displays the
filtered
data
only.

So far, I have only been able to find code that relates to a combo
box.

I would be gratefule if somebody would be able to spare a few
minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is
left
blank
as the database holds about 20,000 records. By selecting an
individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
M

Mr-Re Man

I have input the following and what seems to be happening is that the Teams
part is working but the date isn't, whatever date I input it pulls up
duplicate records. For example, if i input yesterdays date, I get 7 records
and todays date I get the same 7 records.

CODE:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team] = '"
& Me.cboTeams & "'"
End If

End Sub

Allen Browne said:
After the date, and before the OpenReport:

If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If

That assumes Team is a Text field.
Lose the extra quotes if it is a Number field.

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

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

Mr-Re Man said:
Thanks Allan, I have used that code and it works fine, but how do I filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

Allen Browne said:
You said you wanted a message box if there was not date. Here's that
part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate,
"\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Thanks for the quick response. I have downloaded your examples
previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I
have
tried to all morning to work your code into mine, making tweaks here
and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide
the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

:

Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive
example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
strWhere

I have used some code from this discussion group to filter a report.
The
form I have created has two fields, 1 unbound combo box (cboTeams)
and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input
a
date
and then click the button 'Create Report' and it displays the
filtered
data
only.

So far, I have only been able to find code that relates to a combo
box.

I would be gratefule if somebody would be able to spare a few
minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is
left
blank
as the database holds about 20,000 records. By selecting an
individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
M

Mr-Re Man

I think I have solved it, I replaced the OpenReport with

DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, strWhere, strWhere

and it now seems to filter the records.

Mr-Re Man said:
I have input the following and what seems to be happening is that the Teams
part is working but the date isn't, whatever date I input it pulls up
duplicate records. For example, if i input yesterdays date, I get 7 records
and todays date I get the same 7 records.

CODE:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team] = '"
& Me.cboTeams & "'"
End If

End Sub

Allen Browne said:
After the date, and before the OpenReport:

If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If

That assumes Team is a Text field.
Lose the extra quotes if it is a Number field.

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

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

Mr-Re Man said:
Thanks Allan, I have used that code and it works fine, but how do I filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

:

You said you wanted a message box if there was not date. Here's that
part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate,
"\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Thanks for the quick response. I have downloaded your examples
previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I
have
tried to all morning to work your code into mine, making tweaks here
and
there.....but failed.

I was hoping for a snippet of code to input into the existing line, but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide
the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

:

Here's an example that shows how to build the filter string for a date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive
example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
strWhere

I have used some code from this discussion group to filter a report.
The
form I have created has two fields, 1 unbound combo box (cboTeams)
and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown, input
a
date
and then click the button 'Create Report' and it displays the
filtered
data
only.

So far, I have only been able to find code that relates to a combo
box.

I would be gratefule if somebody would be able to spare a few
minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is
left
blank
as the database holds about 20,000 records. By selecting an
individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
A

Allen Browne

You messed up the date format.

Regardless of your local format, in the Where clause (as in a SQL strring),
you need to use the American format, exactly as shown previously.

More info about that:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html

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

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

Mr-Re Man said:
I have input the following and what seems to be happening is that the Teams
part is working but the date isn't, whatever date I input it pulls up
duplicate records. For example, if i input yesterdays date, I get 7
records
and todays date I get the same 7 records.

CODE:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team] =
'"
& Me.cboTeams & "'"
End If

End Sub

Allen Browne said:
After the date, and before the OpenReport:

If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If

That assumes Team is a Text field.
Lose the extra quotes if it is a Number field.

Mr-Re Man said:
Thanks Allan, I have used that code and it works fine, but how do I
filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
"[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

:

You said you wanted a message box if there was not date. Here's that
part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate,
"\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Thanks for the quick response. I have downloaded your examples
previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I
have
tried to all morning to work your code into mine, making tweaks here
and
there.....but failed.

I was hoping for a snippet of code to input into the existing line,
but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide
the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

:

Here's an example that shows how to build the filter string for a
date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive
example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process
is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
strWhere

I have used some code from this discussion group to filter a
report.
The
form I have created has two fields, 1 unbound combo box
(cboTeams)
and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown,
input
a
date
and then click the button 'Create Report' and it displays the
filtered
data
only.

So far, I have only been able to find code that relates to a
combo
box.

I would be gratefule if somebody would be able to spare a few
minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is
left
blank
as the database holds about 20,000 records. By selecting an
individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing
out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

End Sub
 
M

Mr-Re Man

Thank you Allan, you got me there.

Date format changed, report working exactly as I imagined.

Da iawn! (Welsh for well done!)

Allen Browne said:
You messed up the date format.

Regardless of your local format, in the Where clause (as in a SQL strring),
you need to use the American format, exactly as shown previously.

More info about that:
International Date Formats in Access
at:
http://allenbrowne.com/ser-36.html

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

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

Mr-Re Man said:
I have input the following and what seems to be happening is that the Teams
part is working but the date isn't, whatever date I input it pulls up
duplicate records. For example, if i input yesterdays date, I get 7
records
and todays date I get the same 7 records.

CODE:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, , "[Team] =
'"
& Me.cboTeams & "'"
End If

End Sub

Allen Browne said:
After the date, and before the OpenReport:

If Not IsNull(Me.cboTeams) Then
strWhere = strWhere & " AND ([Team] = """ & Me.cboTeams & """)"
End If

That assumes Team is a Text field.
Lose the extra quotes if it is a Number field.

Thanks Allan, I have used that code and it works fine, but how do I
filter
the team and date into the report.

So far, the code I have is:

Private Sub cmdCreateReport_Click()

Dim strWhere As String

If IsNull(Me.txtDate) Then
MsgBox "Please choose a date"
Else
strWhere = "[DateReceived] = " & Format(Me.txtDate,
"\#dd\/mm\/yyyy\#")
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
"[Team]
= '" & Me.cboTeams & "'"
End If

End Sub

thank you

:

You said you wanted a message box if there was not date. Here's that
part:

Dim strWhere As String
If IsNull(Me.txtDate) Then
MsgBox "Pick a date!"
Else
strWhere = "[YourDateField] = " & Format(Me.txtDate,
"\#mm\/dd\/yyyy\#")
End If

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

Reply to group, rather than allenbrowne at mvps dot org.
Thanks for the quick response. I have downloaded your examples
previously,
but found that they didnn't quite fit in with what I was trying to
accomplish. My coding skills are not that great as it is, however I
have
tried to all morning to work your code into mine, making tweaks here
and
there.....but failed.

I was hoping for a snippet of code to input into the existing line,
but
realise that sometimes it may not be that simple.

If you could either guide me a bit further with your code or provide
the
code I require, that would be really helpful.

thank you for taking the time so far to answer my question it is
appreciated.

:

Here's an example that shows how to build the filter string for a
date
field:
Limiting a Report to a Date Range
at:
http://allenbrowne.com/casu-08.html

Once you have that working, you can look at a more comprehensive
example,
offering the user lots of things to filter by (combos, text boxes,
numbers,
text, dates):
Search form - Handle many optional criteria
at:
http://allenbrowne.com/ser-62.html
That example applies the filter string to a form, but the process
is
identical to build the filter for a report. You apply it with:
DoCmd.OpenReport "repSectionsMailSummary", acViewPreview, ,
strWhere

I have used some code from this discussion group to filter a
report.
The
form I have created has two fields, 1 unbound combo box
(cboTeams)
and
1
unbound text box (txtDate).

I need users to be able to select the team from the dropdown,
input
a
date
and then click the button 'Create Report' and it displays the
filtered
data
only.

So far, I have only been able to find code that relates to a
combo
box.

I would be gratefule if somebody would be able to spare a few
minutes
to
provide me with the necessary code to complete my filter.

I also need the code to display a message if the txtDate field is
left
blank
as the database holds about 20,000 records. By selecting an
individual
day
filters out about 100 records.

Also, I would like to preview it on screen prior to it printing
out
automatically like it does at the moment.

My code so far is as follws:

Private Sub cmdCreateReport_Click()

DoCmd.OpenReport "repSectionsMailSummary", , , "[Team] = '" &
Me.cboTeams & "'"

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