visual basic

C

C.J.

i need a way to open my report up using a form. he is the problem i am
running into. here is my code:

Private Sub Command4_Click()
Dim strReport As String 'Monthly Report.
Dim strField As String 'Received Date.
Dim strWhere As String '=Between
[Forms]![frmWhatDate]![txtStartDate] And [Forms]![frmWhatDate]![txtEndDate].
Const conDateFormat = "\#mm\/dd\/yyyy\#"

strReport = "rptMonthly Report"
strField = "Received Date"

strWhere = "1=1 "

If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & " AND " & strField & _
" >= " & Format(Me.txtStartDate, conDateFormat)
End If

If Not IsNull(Me.txtEndDate) Then
strWhere = strWhere & " AND " & strField & _
" <= " & Format(Me.txtEndDate, conDateFormat)
End If

Debug.Print strWhere
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub


Private Sub Command5_Click()
DoCmd.Close acForm, Me.Name
End Sub

the name of my report is Monthly Report. What I am trying to do is use this
form to open my report which has two subreports on it. To open this report
before i added the two subreports, i had to enter two parameters, a start
date and an end date. Once i added the two subreports, it asks for the
parameters five times. once i enter all the parameters. example: start
01/01/08 end 01/31/08, five times then i can preview the data. i have to do
this to print also.

the problem i run into with the above code is that the first line is
highlighted yellow
Private Sub Command4_Click()
and these words are hightlighted gray
txtStartDate
what does this mean?

i need a step by step way to fix this. please be very specific. i an a
beginner with access. all help is greatly appreciated.
 
D

Duane Hookom

As per my previous replies, the form your code is running in doesn't have a
text box named txtStartDate.

If your subreports need to be filtered by the same date range then forget
about attempting this method. You need to open the record sources of your
report and subreports and enter a criteria like:

Between [Forms]![frmWhatDate]![txtStartDate] And
[Forms]![frmWhatDate]![txtEndDate]
 

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