Help with vb command to open a report

tbochman

New member
Local time
Today, 21:33
Joined
May 25, 2001
Messages
8
I am trying to open a report when a user clicks on the button and sue a query to display the results between 2 dates on a form. What I can't figure out is the VB line to open the report. I have "DoCmd.OpenReport stDocName, acPreview, report_sort_by_date" and it gives me a compiler error : variable not defined. "report_sort_by_date" is the name of my query. I can do this with a macro but I want to get it in vb for a little bit cleaner DB. Thanks for your help
Tim
 
This may be more then you are looking for but this code uses two text boxes and a command button. The user puts in a begin date and a end date and clicks the button. The report will open and only show the records that fit the criteria. No need for a parameter query.

Dim bProcOk As Boolean
bProcOk = True

' The following IF Then series checks for null values in
' the stated txtbox. If a null is found the error message
' is displayed and the focus is sent back to form control

If IsNull(Me.txtBeginDate) Then

MsgBox "You must provide a beginning date!", vbExclamation, "Error"
txtBeginDate.SetFocus
bProcOk = False

Else

If IsNull(Me.txtEndDate) Then
MsgBox "You must provide a ending date!", vbExclamation, "Error"
txtEndDate.SetFocus
bProcOk = False

End If
End If

If bProcOk Then ' If the above IF Thens are satisfied
' the following command is carried out

DoCmd.OpenReport "EmpContactLog", acPreview, , _
"[date]>=#" & Me![txtBeginDate] & "# And [date]<= #" & _
Me![txtEndDate] & "#"
' Opens the report based on the begin and end date

End If

Let me know if you want more help with this or if I missed the point of your question entirely.
 
Thanks a bunch that was exactly what I needed.

Tim
 

Users who are viewing this thread

Back
Top Bottom