• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1244
  • Last Modified:

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.
  • 4
  • 2
1 Solution
Jeffrey CoachmanMIS LiasonCommented:
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 CoachmanMIS LiasonCommented:
Sorry, this is better:

If IsNull(Me.Company_Name) Then
    MsgBox "Company name cannot be left blank."
    Cancel = True
End If
mrongAuthor Commented:
The popup message doesn't show up.
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

mrongAuthor Commented:
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 CoachmanMIS LiasonCommented:
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 CoachmanMIS LiasonCommented:
Just to be clear, ..there are odd things that happen when you use Docmd.Close, ..see here:

It in that link it notes that you can get around this by using a "Macro" on the button (instead of VBA) to close the form.

So try this:

Action: Close Window
Object Type: Form
Object Name: YourFormName
Save: Prompt  (Not this is only applicable to save design changes to the form, ...not data changes as you are wanting)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now