Names and Dates
am 09.01.2008 11:04:31 von Elainie
I have a combo box with several names, once a name is selected then it
goes and gets a report of the name of the person that has been
selected.
I would like to put this and date selection on one form, the query
won't run, it says that there is too many parameters.
so select name then select dates that you would like to pull up and
then put this into a report.
Any help would be greatly apprectiated... as no idea where to turn on
this one.
Elaine
Re: Names and Dates
am 09.01.2008 15:02:15 von Salad
Elainie wrote:
> I have a combo box with several names, once a name is selected then it
> goes and gets a report of the name of the person that has been
> selected.
>
> I would like to put this and date selection on one form, the query
> won't run, it says that there is too many parameters.
>
> so select name then select dates that you would like to pull up and
> then put this into a report.
>
> Any help would be greatly apprectiated... as no idea where to turn on
> this one.
>
> Elaine
Assuming the combo is called ComboName and the dates are FromDate and
ToDate and the date field in the table is DateFld, your code make look
something like
Docmd.OpenReport Me.ComboName,,,_
"DateFld Between #" & Me.FromDate & "# And #" Me.ToDate & "#"
This assumes both dates are filled in.
Do you create a separate report for each person's name or did you want
to filter the report on the persons name? Let's pretend you wanted to
filter on a person's name and date range. Your code may be similar to
the following (dates surrounded by #, strings by ' or "")
Dim strFilter as string
If Not IsNull(Me.ComboName) Then
strFilter = "TableNameFld = '" & Me.ComboName & "' And "
Endif
If Not IsNull(Me.FromDate) Then
strFilter = strFilter & "DateFld >= #" & Me.FromDate & "# And "
Endif
If Not IsNull(Me.ToDate) Then
strFilter = strFilter & "DateFld >= #" & Me.ToDate & "# And "
Endif
'if there is a filter, remove the trailing 'And'
If strFilter > "" Then strFilter = Left(strFilter,Len(strFilter)-5)
Docmd.OpenReport YourReportName,,,strFilter