Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this DoCmd.OpenReport command work

Status
Not open for further replies.

tkms

Programmer
Apr 20, 2002
1
US
I have tried everything and still I can't get this where condition to pass to the query and open the report. It works off a command button on the form the date info comes from it has to work this way don't ask why!!!
----------------------------------------------------
Private Sub Start_Click()
On Error GoTo Err_Start_Click

Dim stDocName As String
Dim DateRange As Variant
Dim Installer As String

stDocName = "Installer_Summary_Door"

DateRange = "[Date to Install]=" & ">=#" & Me.Text3 & "#"
DateRange = DateRange & &quot; and &quot; & &quot;<=#&quot; & Me.Text5 & &quot;#&quot;


' The next line works when assigned and sent to docmd
'Installer = &quot;[Installer]='&quot; & Me.Combo0 & &quot;'&quot;

'this just pops up a box to show me the completed statement
MsgBox (DateRange)

DoCmd.OpenReport stDocName, acViewPreview, , DateRange

Exit_Start_Click:
Exit Sub

Err_Start_Click:
MsgBox Err.Description
Resume Exit_Start_Click

End Sub
-------------------------------------------------------
this version gives a
syntax error (missing operator) in query expression
error
I have tried various different combinations others give
a data type mismatch error
any help?????
 
Hi,

I'm not sure if I've understood your question correctly, but here goes.
What you need to do is set the date range in the actual query that underlies the report, not in the code where you call the report.
For example if you had a form called 'Input Form' and a control on the form in which you enter the date, called 'Date', then in the query, in the criteria box for the date you would enter:
Forms![Input Form]![Date]
If you had 2 controls 'Date1' and 'Date2' and wanted dates in between these values you would put:
Between Forms![Input Form]![Date1] And Forms![Input Form]![Date2]
In the code where you call the report you would then put:
DoCmd.OpenReport stDocName, acViewPreview

Hope this is the answer you're looking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top