Open report inputbox criteria

G

Guest

I am trying to open a Access report based on the date input by the user in an
input box. Trying to work with SQL and docmd.openreport statements. Below is
the code and any help would be appreciated.

Public Function ReportFieldOrder()
Dim rptMember As Report, strAsk As String, strSQL As String
strAsk = InputBox("Enter Date", "Date", Date)
DateValue strAsk
strSQL = "Select * from Table1 where [Toda] = " & strAsk

Set rptMember = Application.Reports("rptDateEnrolled")
DoCmd.OpenReport "rptDateEnrolled", acViewNormal, , strSQL

End Function
 
G

Guest

One thing I see is that the line:
DateValue strAsk
will do nothing. If what you are trying to do is see if strAsk is a valid
date, see the change below

Also, I don't think this line does anything
Set rptMember = Application.Reports("rptDateEnrolled")

And Last, I still don't think it will work.
DoCmd.OpenReport "rptDateEnrolled", acViewNormal, , strSQL
In this line where you have strSQL, waht the OpenReport is looking for is
the name of a saved query; however, the next argument, the Where condition
will do what you want if you have the record source of your report set to a
stored query or a table that has the data your report needs and [Toda] as one
of it's fields.

Public Function ReportFieldOrder()
Dim strAsk As String
Dim strWhere As String

Do While True
strAsk = InputBox("Enter Date", "Date", Date)
If IsDate(strAsk) Then
Exit Do
Else
If MsgBox("InValid Date Entered", vbExclamation + vbRetryCancel) _
= vbCancel Then
Exit Function
End If
Loop

strWhere = "[Toda] = #" & strAsk & "#"
'Dates need to be enclosed in #

DoCmd.OpenReport "rptDateEnrolled", acViewNormal, , , strWhere

End Function
 

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

Similar Threads


Top