Combine Code

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
 
G

Guest

What exactly are you trying to achieve? If you mean call both sets of code,
you could simply have
call Command5_click
call cmdSendReport_click

in your code.

Please be more specific with your issue.

Damian.
 
G

Guest

Damian, I figured it out....I used

Me.cmdSendReport.Requery

Your response forced me to think about what I really wanted the program to
do in steps...thanks for the mental push!!
Damian S said:
What exactly are you trying to achieve? If you mean call both sets of code,
you could simply have
call Command5_click
call cmdSendReport_click

in your code.

Please be more specific with your issue.

Damian.

Please help James said:
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
 

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