Using Msgbox (1 Viewer)

Rob.Mills

Registered User.
Local time
Today, 02:02
Joined
Aug 29, 2002
Messages
871
I have setup a command button to email a user and that email will pull information from the record.

The problem exists in an if statement I have made. What I wanted was for it to test the value of a combobox. If the combobox equals 3 then it will open a msgbox to confirm that I want to email. Then I want to be able to say no and then for it to jump out of the function and forget the rest. When I tested it the msgobx opened. I clicked no but it still ran thru the rest of the code. Any ideas??


Private Sub cmdNotify_Click()

On Error GoTo ErrHandler

Dim objOutlook As Outlook.Application
Dim objOutlookmsg As Outlook.MailItem
Dim strTo As String, strSubject As String, strBody As String
Dim strPayee As String, strZC As String, dtm As Date, strCounty As String, strState As String

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookmsg = objOutlook.CreateItem(olMailItem)
strTo = DLookup("[txtFirst]", "tblNames", "[txtID]=" & Me!txtRequestor) & "." & DLookup("[txtLast]", "tblNames", "[txtID]=" & Me!txtRequestor) & "@zcsterling.com"
strSubject = "Completed Request"
strPayee = Me!txtPayee.Value
strZC = Me!txtVendor.Value
dtm = Me!txtDate.Value

If Me!cboStatus = 3 Then
MsgBox "This entry has been marked complete. Are you sure you want to send an email?", vbYesNo
If Response = vbNo Then
GoTo Exit_cmdNotify_Click
End If
End If

If IsNull(txtCounty) Then
strCounty = Me!txtCity.Value
Else
strCounty = Me!txtCounty.Value
End If
strState = Me!txtState.Value
strBody = "The request you made for " & strPayee & ", ZC code " & strZC & ", "
strBody = strBody & "on " & dtm & " in " & strCounty & ", " & strState & " has been completed."
strBody = strBody & vbCrLf & vbCrLf & "Rob Mills"

With objOutlookmsg
.To = strTo
.Subject = strSubject
.Body = strBody
.Send
End With

Me!txtDateComp.Value = Now
Me!cboStatus = 3

Exit_cmdNotify_Click:
Exit Sub

ErrHandler:
Resume Exit_cmdNotify_Click

End Sub
 

Nero

Shop smart, shop S-Mart
Local time
Today, 07:02
Joined
Jan 8, 2002
Messages
217
Dim Response

Response = MsgBox "This entry has been marked complete. Are you sure you want to send an email?", vbYesNo
If Response = vbNo Then
Exit Sub
End If
 

Users who are viewing this thread

Top Bottom