email validation fails
am 24.01.2008 21:22:01 von 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
Re: email validation fails
am 25.01.2008 03:34:03 von Allen Browne
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" wrote in message
news:6a3a3940-47cc-419a-a07e-e3a1d0e487ae@e4g2000hsg.googleg roups.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