Does it happen that one of the fields is empty, but you need it to return all
the records in that case?
Try
strCriteria = "[Num1]=" & Me.Num1 & _
" And [Text1] Like'" & Nz(Me.Text1,"*") & "'" & _
" and [Text2] Like '" & Nz(Me.Text2,"*") & "'" & _
" and [Text3] Like '" & Nz(Me.Text3,"*") & "'" & _
" and [Num2]=" & Me.Num2 & _
" and [Date1] between #" & Me.Date1 & "# and #" & Me.Date1 & "#"
--
HTH, Good Luck
BS"D
:
Yes, the control source of the report has no filter. It includes all the
records.
If I run the report independently (without thru form), it will show all the
records from the table where the records are.
Thanks.
:
Does the reprt record source has all the records selected, with no filter?
An extra filter might limit the amount of records before the WherCondition
of the report.
--
HTH, Good Luck
BS"D
:
Hi Ofer,
Thanks for your help. I still need a little more help. Below is the code
that I have. When I click to print the report, it gives me the report, but
the report does not have the same info as on the form. I will give you a
scenario at the end of code.
Private Sub cmdPrint_Click()
On Error GoTo Err_cmdPrint_Click
Dim strCriteria As String
If Me.Dirty Then 'Save any edits
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print.
MsgBox "No record to print."
Else
strCriteria = "[Num1]=" & Me.Num1 & _
"And [Text1]='" & Me.Text1 & "'" & _
"and [Text2]='" & Me.Text2 & "'" & _
"and [Text3]='" & Me.Text3 & "'" & _
"and [Num2]=" & Me.Num2 & _
"and [Date1] between #" & Me.Date1 & "# and #" & Me.Date1 & "#"
DoCmd.OpenReport "rptUnarchive_T&E_by_Client_ID", acViewPreview, ,
strCriteria
DoCmd.Close acForm, "frmUnarchive_T&E_by_Client_ID"
End If
Exit_cmdPrint_Click:
Exit Sub
Err_cmdPrint_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Click
End Sub
Here is a scenario:
I run the form based on 3 criteria (out of 5): Text1, Text3 and Date1. The
form returns 8 records, but the report shows only 2 records (out of 8).
On the form, since I didn't type in Num1 as one of my criteria, it gives me
2 (the report has just 1). Also I picked the date range (Date1) from
07/01/04 to 07/31/04. The form shows 2 records for 07/03/04, 3 records for
07/10/04 and etc. On the other hand, the report only shows the 2 records for
07/03/04.
Apparently, the report is only picking up the first records that meet all
the criteria.
As far as the code for date range, there is only one field for date. I
don't have a field for Beginning Date and Ending Date (only Date1). I use
the "Between And" in my query to allow the user to type in a date range.
So in the code:
strCriteria = "[DateField] Between #" & Me![Beginning Date] & "# And #" &
Me![Ending Date ] & "#"
The Beginning Date and Ending Date fields do I have them the same as the
DateField (Date1)?
Again, I really appreciate your help.
:
First try this link
http://www.databasedev.co.uk/report_from_form_record.html
To add to the filter in the example
For Number
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID]
For Text add single quote
strCriteria = "[lngSalespersonID]= '" & Me![lngSalespersonID] & "'"
For Date add #
strCriteria = "[lngSalespersonID]= #" & Me![lngSalespersonID] & "#"
To filter on few fields
strCriteria = "[lngSalespersonID]= " & Me![lngSalespersonID] & " And
[TextField] = '" & Me![TextFieldName] & "'"
Or for two dates something like
strCriteria = "[DateField] Between #" & Me![Beginning Date] & "# And #" &
Me![Ending Date ] & "#"
--
HTH, Good Luck
BS"D
:
Hello all,
I have a report which prompts the user with 5 parameters (criteria) when the
form is opened. 5 parameters are: Student ID, Student Group, Beginning Date,
Ending Date and Grade. Beginning Date and Ending Date are the only two
required fields.
The form then would show the records based on the selected criteria. I also
have a report created, and I would like to have the report shows the exact
same records from the form. How can I write the code to connect the form and
report to show the exact same records from the form?
Thanks.