I have a form in Access and I am having a hard time with a VBA script. What I am trying to do is click on a button I created called Generate ECM report. I want to be able to type in a beginning date and a ending date to generate this ECM report. The script I have below is:
Private Sub Generate_ECM_Report_Click()
On Error GoTo Err_Generate_ECM_Report_Click
Dim stDocName As String
Dim stWhere As String
If Not IsDate(Me.txtBeginning) And IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] <= " & SQLDate(Me.txtEnding)
ElseIf IsDate(Me.txtBeginning) And Not IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] >= " & SQLDate(Me.txtBeginning)
ElseIf IsDate(Me.txtBeginning) And IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] Between " & SQLDate(Me.txtBeginning) & "And" & SQLDate(Me.txtEnding)
End If
'MsgBox stWhere
Debug.Print "Beginning: " & Me.txtBeginning & "Ending: " & Me.txtEnding & " StWhere: " & stWhere
DoCmd.OpenReport stDocName, acViewPreview, , stWhere
Exit_Generate_ECM_Report_Click:
Exit Sub
Err_Generate_ECM_Report_Click:
MsgBox Err.Description
End Sub
When I click on the button Generate ECM report I get the following error message:
The action or method requires a Report name argument. Can you tell me ehat that means and can you help me with this script in VBA?
Private Sub Generate_ECM_Report_Click()
On Error GoTo Err_Generate_ECM_Report_Click
Dim stDocName As String
Dim stWhere As String
If Not IsDate(Me.txtBeginning) And IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] <= " & SQLDate(Me.txtEnding)
ElseIf IsDate(Me.txtBeginning) And Not IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] >= " & SQLDate(Me.txtBeginning)
ElseIf IsDate(Me.txtBeginning) And IsDate(Me.txtEnding) Then
stWhere = "[DateCreated] Between " & SQLDate(Me.txtBeginning) & "And" & SQLDate(Me.txtEnding)
End If
'MsgBox stWhere
Debug.Print "Beginning: " & Me.txtBeginning & "Ending: " & Me.txtEnding & " StWhere: " & stWhere
DoCmd.OpenReport stDocName, acViewPreview, , stWhere
Exit_Generate_ECM_Report_Click:
Exit Sub
Err_Generate_ECM_Report_Click:
MsgBox Err.Description
End Sub
When I click on the button Generate ECM report I get the following error message:
The action or method requires a Report name argument. Can you tell me ehat that means and can you help me with this script in VBA?