Can someone help me out here, I have db a few w/required fields and a command button that sents out a simple email msg from a module. Problem is users are clicking the email button when all the fields aren't being filled in. How would I code it so this doesn't occur?
This is my code on the command button
OpenEmailRequestFraser
which opens
Option Compare Database
Option Explicit
Sub OpenEmailRequestFraser()
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("tblEmailRequestFraser") 'table where email is
strEmail = rsEmail.Fields("dEmailAddress").Value
rsEmail.MoveNext
Do While Not rsEmail.EOF
strEmail = strEmail & " ; " & rsEmail.Fields("dEmailAddress").Value
rsEmail.MoveNext
Loop
DoCmd.SendObject , , , strEmail, , , "Maintenance Work Request", "Maintenance request Number #" _
& " " & Forms!frmRequestFraser.RequestNo & " " & "has been entered into the system by" _
& " " & Forms!frmRequestFraser.RequestedBy & " on " & " " & Format(Forms!frmRequestFraser.DateSubmitted, _
"dddd mmm d, yyyy") & " at" & " " & Format(Forms!frmRequestFraser.TimeIn, "hh:mm AMPM") & _
" " & "which is due for completion" & " " & Format(Forms!frmRequestFraser.CompletionRequestDate, "dddd mmm d, yyyy") _
& "." & vbCrLf & "The Suspect problem is: " & Forms!frmRequestFraser.Combo22.Column(1) & " , " & "Equipment Location" & _
Forms!frmRequestFraser.LocationEquipment & ", " & Forms!frmRequestFraser.SuspectedProblem & ", ", False, ""
' _put a comma after the machine type, there was a " ", second line from the button
Set rsEmail = Nothing
MsgBox "Email notifications have been sent"
End Sub
This works fine!
Private Sub Form_BeforeUpdate(Cancel As Integer)
'ea of 3 controls under properties: All: Tags set to Required
I tried using the line, borrowed from another db, it was placed right after OpenEmailRequestFraser, but the messages still get sent
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "Field(s)indicated in red must contain data. ", vbCritical + vbOKOnly + vbDefaultButton1, "Required Information Missing"
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing
End Sub
This is my code on the command button
OpenEmailRequestFraser
which opens
Option Compare Database
Option Explicit
Sub OpenEmailRequestFraser()
Dim rsEmail As DAO.Recordset
Dim strEmail As String
Set rsEmail = CurrentDb.OpenRecordset("tblEmailRequestFraser") 'table where email is
strEmail = rsEmail.Fields("dEmailAddress").Value
rsEmail.MoveNext
Do While Not rsEmail.EOF
strEmail = strEmail & " ; " & rsEmail.Fields("dEmailAddress").Value
rsEmail.MoveNext
Loop
DoCmd.SendObject , , , strEmail, , , "Maintenance Work Request", "Maintenance request Number #" _
& " " & Forms!frmRequestFraser.RequestNo & " " & "has been entered into the system by" _
& " " & Forms!frmRequestFraser.RequestedBy & " on " & " " & Format(Forms!frmRequestFraser.DateSubmitted, _
"dddd mmm d, yyyy") & " at" & " " & Format(Forms!frmRequestFraser.TimeIn, "hh:mm AMPM") & _
" " & "which is due for completion" & " " & Format(Forms!frmRequestFraser.CompletionRequestDate, "dddd mmm d, yyyy") _
& "." & vbCrLf & "The Suspect problem is: " & Forms!frmRequestFraser.Combo22.Column(1) & " , " & "Equipment Location" & _
Forms!frmRequestFraser.LocationEquipment & ", " & Forms!frmRequestFraser.SuspectedProblem & ", ", False, ""
' _put a comma after the machine type, there was a " ", second line from the button
Set rsEmail = Nothing
MsgBox "Email notifications have been sent"
End Sub
This works fine!
Private Sub Form_BeforeUpdate(Cancel As Integer)
'ea of 3 controls under properties: All: Tags set to Required
I tried using the line, borrowed from another db, it was placed right after OpenEmailRequestFraser, but the messages still get sent
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True
For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
MsgBox "Field(s)indicated in red must contain data. ", vbCritical + vbOKOnly + vbDefaultButton1, "Required Information Missing"
Cancel = True
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing
End Sub