I have the following code, that copy records to a new table, and also sends email with those fields. I would like to prevent email from popping up if a condition is not met: Here is my code, that is associated with a command button:
Private Sub Command124_Click()
On Error GoTo Err_Command124_Click
Dim db As DAO.Database, rst As DAO.Recordset
'Copy Record and Save Record to new table
Set db = CurrentDb
Set rst = db.OpenRecordset("tbl_NameOfTable"
rst.AddNew
rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3
rst!field4 = Me!field4
If IsNull(Me.field1) And IsNull(Me.field3) And IsNull(Me.field3) And IsNull(Me.field4) Then
MsgBox "You must enter text for field1 or field2, or field3 or field4", vbExclamation
field1.SetFocus
End If
rst.Update
rst.Close
db.Close
'send email
DoCmd.SendObject acSendNoObject, "", acFormatTXT, "emailaddresshere",,,"SubjectHere", "BodyTextHere, " & Me!field1 & ", " & Me!field2 & ", " & Me!field3 & ", " & Me!field4, True
Exit_Command124_Click:
Exit Sub
Err_Command124_Click:
MsgBox Err.Description
Resume Exit_Command124_Click
End Sub
The problem I'm having with this code, is when I hit the command button, and field 1 thru 4 are not populated, it goes ahead and brings up the email window, which is not correct. I would like for the code not to bring up the email window, until field 1 or field2, or field 3 or field 4 is populated.
Can someone help me with this. I bet it's something easy I'm not doing here.
Thanks to all.
Private Sub Command124_Click()
On Error GoTo Err_Command124_Click
Dim db As DAO.Database, rst As DAO.Recordset
'Copy Record and Save Record to new table
Set db = CurrentDb
Set rst = db.OpenRecordset("tbl_NameOfTable"
rst.AddNew
rst!field1 = Me!field1
rst!field2 = Me!field2
rst!field3 = Me!field3
rst!field4 = Me!field4
If IsNull(Me.field1) And IsNull(Me.field3) And IsNull(Me.field3) And IsNull(Me.field4) Then
MsgBox "You must enter text for field1 or field2, or field3 or field4", vbExclamation
field1.SetFocus
End If
rst.Update
rst.Close
db.Close
'send email
DoCmd.SendObject acSendNoObject, "", acFormatTXT, "emailaddresshere",,,"SubjectHere", "BodyTextHere, " & Me!field1 & ", " & Me!field2 & ", " & Me!field3 & ", " & Me!field4, True
Exit_Command124_Click:
Exit Sub
Err_Command124_Click:
MsgBox Err.Description
Resume Exit_Command124_Click
End Sub
The problem I'm having with this code, is when I hit the command button, and field 1 thru 4 are not populated, it goes ahead and brings up the email window, which is not correct. I would like for the code not to bring up the email window, until field 1 or field2, or field 3 or field 4 is populated.
Can someone help me with this. I bet it's something easy I'm not doing here.
Thanks to all.