G
Guest
Does anyone know the best way to incorpoarte two seperate codes into one.
Thanks!
Code 1
Private Sub Command5_Click()
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strReport = "rptEmployeeData"
strField = "dateactive"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " <= " & Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " >= " & Format(Me.txtStartDate,
conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
Code 2
Private Sub cmdSendReport_Click()
On Error GoTo PROC_ERR
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strAcountStatus As String
Dim strEmail As String
Dim strUserID As String
Dim fOk As Boolean
strSQL = "SELECT UserID, Email From [rptlstusers]"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
DoCmd.OpenReport "rptEmployeeData", acPreview
Reports![rptEmployeeData].FilterOn = True
Do While Not rst.EOF
strEmail = rst.Fields("Email")
strUserID = rst.Fields("UserID")
DoEvents
fOk = SendReportByEmail("rptEmployeeData", strEmail)
If Not fOk Then
MsgBox "Delivery Failure to the following email address: " & strEmail
rst.MoveNext
End If
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub
Thanks!
Code 1
Private Sub Command5_Click()
Dim strReport As String
Dim strField As String
Dim strWhere As String
Const conDateFormat = "\#mm\/dd\/yyyy\#"
strReport = "rptEmployeeData"
strField = "dateactive"
If IsNull(Me.txtStartDate) Then
If Not IsNull(Me.txtEndDate) Then
strWhere = strField & " <= " & Format(Me.txtEndDate,
conDateFormat)
End If
Else
If IsNull(Me.txtEndDate) Then
strWhere = strField & " >= " & Format(Me.txtStartDate,
conDateFormat)
Else
strWhere = strField & " Between " & Format(Me.txtStartDate,
conDateFormat) _
& " And " & Format(Me.txtEndDate, conDateFormat)
End If
End If
DoCmd.OpenReport strReport, acViewPreview, , strWhere
End Sub
Code 2
Private Sub cmdSendReport_Click()
On Error GoTo PROC_ERR
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim strAcountStatus As String
Dim strEmail As String
Dim strUserID As String
Dim fOk As Boolean
strSQL = "SELECT UserID, Email From [rptlstusers]"
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
DoCmd.OpenReport "rptEmployeeData", acPreview
Reports![rptEmployeeData].FilterOn = True
Do While Not rst.EOF
strEmail = rst.Fields("Email")
strUserID = rst.Fields("UserID")
DoEvents
fOk = SendReportByEmail("rptEmployeeData", strEmail)
If Not fOk Then
MsgBox "Delivery Failure to the following email address: " & strEmail
rst.MoveNext
End If
Loop
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
PROC_EXIT:
Exit Sub
PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT
End Sub