dbTalk Databases Forums  

email validation fails

comp.databases.ms-access comp.databases.ms-access


Discuss email validation fails in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
T
 
Posts: n/a

Default email validation fails - 01-24-2008 , 02:22 PM






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



Reply With Quote
  #2  
Old   
Allen Browne
 
Posts: n/a

Default Re: email validation fails - 01-24-2008 , 08:34 PM






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" <teiben (AT) wideopenwest (DOT) com> wrote

Quote:
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


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.