Frustrating Form Coding Error

  • Thread starter Thread starter Scot Dever
  • Start date Start date
S

Scot Dever

I am trying to create a simple user defined report form for a range of
records between a chosen start and end date but keep getting this compile and
syntax error instead of the report, am I missing something?

Private Sub Command4_Click()

Dim ReportName
ReportName = "Stores Start Order" _
DoCmd.OpenReport _
ReportName:=ReportName, _
view:=acViewPreview, _
WhereCondition:="[StartConstCur]between #"& _
Me.StartDate& "# and #" & _
Me.EndDAte & "#"

End Sub
 
Get rid of the underscore after ReportName = "Stores Start Order". With it
there, you're saying that the following line(s) are part of the same
statement.

You might also want to put a space between the field name and the keyword
between in the WhereCondition.

Private Sub Command4_Click()

Dim ReportName As String

ReportName = "Stores Start Order"

DoCmd.OpenReport _
ReportName:=ReportName, _
view:=acViewPreview, _
WhereCondition:="[StartConstCur] between #"& _
Me.StartDate& "# and #" & _
Me.EndDAte & "#"

End Sub

although to ensure it'll work for all users, regardless of their regional
settings, you'd be better off using

Private Sub Command4_Click()

Dim ReportName As String

ReportName = "Stores Start Order"

DoCmd.OpenReport _
ReportName:=ReportName, _
view:=acViewPreview, _
WhereCondition:="[StartConstCur] between "& _
Format(Me.StartDate, "\#yyyy\-mm\-dd\#") & " and " & _
Format(Me.EndDate, "\#yyyy\-mm\-dd\#")

End Sub
 
Thank You Doug, Quick follow up. Can I insert this code into ay report,
changing the report name and where condition appropriately of coarse
 
That code should be on a form, not a report.

Yes, you can change the report name and condition and run it anywhere.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Scot Dever said:
Thank You Doug, Quick follow up. Can I insert this code into ay report,
changing the report name and where condition appropriately of coarse

Scot Dever said:
I am trying to create a simple user defined report form for a range of
records between a chosen start and end date but keep getting this compile
and
syntax error instead of the report, am I missing something?

Private Sub Command4_Click()

Dim ReportName
ReportName = "Stores Start Order" _
DoCmd.OpenReport _
ReportName:=ReportName, _
view:=acViewPreview, _
WhereCondition:="[StartConstCur]between #"& _
Me.StartDate& "# and #" & _
Me.EndDAte & "#"

End Sub
 
Back
Top