Avatar of mrong
mrong asked on

Popup message before saving record in Access 2013 Form


I have a field named Company_Name on my Access 2013 form. I want to add a event on the form. If Company_Name is blank when the users try to add/save the data, it will popup a message say "Company Name is required". The data won't be saved untill Company_Name if filled out.

Please provide sample code.

Thanks  in advance.
Microsoft AccessVisual Basic Classic

Avatar of undefined
Last Comment
Jeffrey Coachman

8/22/2022 - Mon
Jeffrey Coachman

On the before Update event of the form try something like this:

If me.Company_Name="" Then
    msgbox "Company name cannot be left blank."
End if
Jeffrey Coachman

Sorry, this is better:

If IsNull(Me.Company_Name) Then
    MsgBox "Company name cannot be left blank."
    Cancel = True
End If

The popup message doesn't show up.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

ok, the popup shows up.

I have a save button on the form with the following code. If the user leaves Company_Name blank, it will popup the message then just close the form itself. Is there anyway to have the form stays unless user close the form?

Jeffrey Coachman

The presence of this button was not mentioned in your original post...

What you have there is not really a "Save" button, the code you have there Closes the form.
So this is really a "Close Button"

You button will force the form to close regardless..

If it were me, I would delete this button and tell users to use the standard "X" in the upper right hand of the form.
The standard "X" will allow the "validation" code to run as you specify.

Jeffrey Coachman

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question