Dont send email object with out entering fields VBA!!

dtaylor89

Registered User.
Local time
Today, 16:05
Joined
Jan 16, 2013
Messages
25
Hi, How are you access developers doing?
I'm in need of a little help. I have a form with 6 fields, all these fields are required. I've been trying to figure out how to not allow the user to send the email if either of the required field(s) is blank. Along with setting focus to the first field that is null.

Does anyone have any suggestions?
 
This type of thing:

Code:
If Len(Me.SomeControl & vbNullString) = 0 Then
  MsgBox "You need to fill out SomeControl"
  Me.SomeControl.SetFocus
  Exit Sub
End If
 
Hello dtaylor89, Welcome to AWF.. :)

You need to check all the TextBox control and Exit Sub if it encounters a Null control.. Something like..
Code:
Private Sub sendEmailBtn_OnClick()
    If Len(Me.[COLOR=Blue]textBox1[/COLOR] & vbNullString) = 0 Then
        Call MsgBox("Text Box 1 is a Required Field, please enter the information", vbCritical)
        Me.[COLOR=Blue]textBox1[/COLOR].SetFocus
        Exit Sub
    End If
    
    If Len(Me.[COLOR=Blue]textBox2 [/COLOR]& vbNullString) = 0 Then
        Call MsgBox("Text Box 2 is a Required Field, please enter the information", vbCritical)
        Me.[COLOR=Blue]textBox2[/COLOR].SetFocus
        Exit Sub
    End If
    :
    :
    [COLOR=Green]'procedure to send email continues.. [/COLOR]
    :
End Sub
Change blue bits..

I think I was a bit slow there.. :p
 
Last edited:
The code I wrote will only give a message box on the first failed test, then exit. If you want a message for all, build a string variable containing any failed test and only give the message box at the end if the variable has been populated.
 
Thanks pbaldy and pr2-eugin you guys really helped me out alot. I really appreciate it.
 
Happy to help, and welcome to the site!
 

Users who are viewing this thread

Back
Top Bottom