Best way to select records

  • Thread starter Thread starter Alex H
  • Start date Start date
A

Alex H

Hi

From a control on a form, I select a date. i then need to select all
records within a tables, where the date selected matched a date field, and
then preview a report.

What is the best way to select the records - predefined query or dlookup or
an sql statement?

Thanks
A
 
The best approach is to use the "where" clause of the open report command.

Lets assume your date control/text box on the form is call

txtInvoiceDate


You code to open the form with just the selected dates would be:

dim strWhere as string

if isnull(me.txtInvoiceDate) = false then

strWhere = "InvoiceDate = #" & format(me.txtInvoiceDate,"mm/dd/yyyy") &
"#"

end if

docmd.OpenReport "yourreport",acviewPreview,,strWhere

The above is nice, since then you don't have to mess with query parameters,
or modify the reports sql. I make report prompt screens all the time. Here
is some screen shots that uses the above code:

http://www.members.shaw.ca/AlbertKallal/ridesrpt/ridesrpt.html
 
Thanks Albert - that was a great deal of trouble you went to - and it
worked.

By the way - I'll have four tickets on the pubcrawl tour :)

A
 
Back
Top