By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,218 Members | 1,326 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,218 IT Pros & Developers. It's quick & easy.

email validation fails

P: n/a
T
I have a db w/3 required fields, I'm using the follow code to validate
on the forms before update, which works fine. Problem is user are
selecting the command button, which sends out an email message, I
don't want the message sent out unless the required fields are filled
out.

I've tried a few different lines of code w/no success, the portion in
between ---------------

Private Sub cmdSendEmail_Click()
'ea of 3 controls under properties: All: Tags set to Required

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
' If Nz(ctl, "") = "" Then Tried this too
MsgBox "Field(s)indicated in red must contain data. ",
vbCritical + vbOKOnly + vbDefaultButton1, "Required Information
Missing"
--------------------------------------------------------------------------------------------------
DoCmd.CancelEvent
Exit Sub
'Cancel = True
--------------------------------------------------------------------------------------------------
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing

OpenEmailRequestFraser
End Sub

Any idea'ws
Jan 24 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You can't use CancelEvent in this context, because it's not a cancelable
event.

When your code performs the Exit For, it continues down and calls
OpenEmailRequestFraser, which is what you are trying to avoid.

Try something like this:

Dim blnContinue As Boolean
Dim ctl As Control
Dim bCancel = True

For Each ctl In Me.Controls
If ctl.Tag = "Required" Then
If IsNull(ctl) Then
bCancel = True
Exit For
End If
End If
Next ctl
Set ctl = Nothing

If bCancel Then
MsgBox "Fields ...
Else
OpenEmailRequestFraser
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"T" <te****@wideopenwest.comwrote in message
news:6a**********************************@e4g2000h sg.googlegroups.com...
>I have a db w/3 required fields, I'm using the follow code to validate
on the forms before update, which works fine. Problem is user are
selecting the command button, which sends out an email message, I
don't want the message sent out unless the required fields are filled
out.

I've tried a few different lines of code w/no success, the portion in
between ---------------

Private Sub cmdSendEmail_Click()
'ea of 3 controls under properties: All: Tags set to Required

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
' If Nz(ctl, "") = "" Then Tried this too
MsgBox "Field(s)indicated in red must contain data. ",
vbCritical + vbOKOnly + vbDefaultButton1, "Required Information
Missing"
--------------------------------------------------------------------------------------------------
DoCmd.CancelEvent
Exit Sub
'Cancel = True
--------------------------------------------------------------------------------------------------
ctl.SetFocus
Exit For
End If
End If
Next ctl
Set ctl = Nothing

OpenEmailRequestFraser
End Sub
Jan 25 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.