VB Help Please

S

SG

I have a form called Print Dialogue

On this for I have 2 unbound Text boxes 1 called StartDate and the other
called EndDate, also on this form I have a commandbutton

The following code is attached the onload event of the form ...


Private Sub Form_Load()
Dim DateRange As New Recordset
DateRange.Open _
"SELECT Min(DateValue(InvoiceDate)) as SDate," & _
"Max(DateValue(InvoiceDate)) as Edate " & _
"From tblinvoice", _
CurrentProject.Connection
Me.Startdate = DateRange!Sdate
Me.EndDate = DateRange!EDate

End Sub

And behind the Onclick even of the command button...

Private Sub Command4_Click()
Dim ReportName
ReportName = "SalesReport1"
DoCmd.OpenReport _
ReportName:=ReportName, _
view:=acViewPreview, _
WhereCondition:="InvoiceDate Between #" & _
Me.Startdate & "# AND #" & _
Me.EndDate & "#"
End Sub

The problem I have with the above is when I click on the command button I
get an MS Access has encountered a problem and needs to close message??

Can anyone help me out on this one, I've checked the code over and over and
cant seem to find a problem.

Thanks in advance

S
 
J

Jeff L

Try this instead:

Private Sub Command4_Click()
Dim ReportName
ReportName = "SalesReport1"
DoCmd.OpenReport ReportName, acViewPreview, ,"InvoiceDate
Between #" & _
Me.Startdate & "# AND #" & _
Me.EndDate & "#"
End Sub

Hope that helps!
 

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

Top