Before Update Code Being Ignored (1 Viewer)

andigirlsc

Registered User.
Local time
Today, 13:53
Joined
Jun 4, 2014
Messages
59
@vbaInet, Yes, I realize that Post #3 has the correct code. As I said, I originally left some lines of code out for reasons that don't quite make sense. Post #19 was used to show my corrections. Thanks for all of your help!

Thanks again to everyone who replied!
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 02:53
Joined
Jan 5, 2009
Messages
5,041
Here is the code for the Bound form Before Update event:

Code:
'------------------------------------------------------------
' Form_BeforeUpdate(Cancel As Integer)
' Validation that requires user to enter first name, last
' name and username to save a record.
'
'------------------------------------------------------------

Private Sub Form_BeforeUpdate(Cancel As Integer)

If Len([txtFirstName] & vbNullString) = 0 Then
    [COLOR=red]MsgBox "Please enter a First Name.", vbOK + vbExclamation + 
[/COLOR]  vbDefaultButton2, "Empty Field"

ElseIf Len([txtLastName] & vbNullString) = 0 Then
    [COLOR=red]MsgBox "Please enter a Last Name.", vbOK + vbExclamation + 
[/COLOR]  vbDefaultButton2, "Empty Field"

ElseIf Len([txtUserID] & vbNullString) = 0 Then
   [COLOR=red]MsgBox "Please enter a UserID Name.", vbOK + vbExclamation +[/COLOR] 
    vbDefaultButton2, "Empty Field"
End If

If Not IsNull(Me.txtFirstName) Then
    If Not IsNull(Me.txtLastName) Then
        If Not IsNull(Me.txtUserID) Then
            MsgBox "A new user has been successfully added to the 
             [COLOR=red]database.", vbInformation + vbOKOnly, "User Update"
[/COLOR]      End If
    End If
End If
End Sub
If you go to the top of the page does it start with the following Code.
Code:
Option Compare Database
Option Explicit
Next is to look at all the items in RED.

These are all incorrect. Have you tried to compile your code? You need to do this.

This should at lease get your Code to work. Then you can have a closer look to see what the problem is.

If you can't get it going I suggest you post a sample database to highlight you problem.

I just created one in 5 Minutes. So it does not take long.

When you do this please use Access 2003. Not everybody can afford to own all the latest versions.
If it does not then I would suggest you change it so it does.
 

andigirlsc

Registered User.
Local time
Today, 13:53
Joined
Jun 4, 2014
Messages
59
@RainLover,
Yes, the top of the code window contains:
Code:
Option Compare Database
Option Explicit
As vbaInet mentioned, everything is working properly now. The code you marked in red is working fine as well. Please see posts #19 and #21. Thank you for your help in this as well!
 

RainLover

VIP From a land downunder
Local time
Tomorrow, 02:53
Joined
Jan 5, 2009
Messages
5,041
Hey guys,

What happened is that I received an Email message so I answered it. Because I came in that way I did not see a SOLVED notice.

Did not make me happy when I realised.

andigirlsc. Do you know how to step through code. If not you should learn. It could help you a lot.
 

vbaInet

AWF VIP
Local time
Today, 17:53
Joined
Jan 22, 2010
Messages
26,374
I disabled the e-mail notification so I tend to login and read through posts that I've missed before replying.

You weren't happy that the thread was marked solved? ;)
 

andigirlsc

Registered User.
Local time
Today, 13:53
Joined
Jun 4, 2014
Messages
59
@RainLover, Thank you for your help! I am very familiar with stepping through code, though. As I mentioned in Post #1, I inherited a form and was trying to use it as is. I have programming experience in C++ and VBA, but I'm still learning each day. I am really enjoying myself!
 

Users who are viewing this thread

Top Bottom