By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,985 Members | 2,907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,985 IT Pros & Developers. It's quick & easy.

Require Selection in Combo before Running a Save Macro.

P: 36
I would like all combo boxes to have require data before the following macro is run from a button:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command128_Click()
  2. Dim Msg, Style, Title, Help, Ctxt, Response, MyString
  3. Msg = "Please Verify Work Stream and Process"   ' Define message.
  4. Style = vbYesNo + vbInformation + vbDefaultButton2   ' Define buttons.
  5. Title = "Verify Data"   ' Define title.
  6. Help = "DEMO.HLP"   ' Define Help file.
  7. Ctxt = 1000   ' Define topic
  8.       ' context.
  9.       ' Display message.
  10. Response = MsgBox(Msg, Style, Title, Help, Ctxt)
  11. If Response = vbYes Then   ' User chose Yes.
  12.    DoCmd.RunMacro ("Save")  ' Perform some action.
  13. Else   ' User chose No.
  14.    MyString = "No"   ' Perform some action.
  15. End If
  16. End Sub
I've the Table has it required and the form has a validation rule of IS NOT NULL, However it still allows to move on and and error message is not sent.
Feb 15 '10 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 2.5K+
P: 2,545
Hi. You should use the BeforeUpdate event of the form as the location of your validation checks, as you can cancel the update if you find that all required fields are not yet filled. Cancelling the update is done by setting the Cancel argument (supplied in the parameter list of the BeforeUpdate event header) to True before you exit the sub.

There is not normally a need for an explicit call to save a record if you use this approach, as the BeforeUpdate event occurs when a user has updated a record and moves to another, or closes the form (both of which, as you have found, bypass users pressing any 'Save' button you put on the form).

Feb 17 '10 #2

P: 36
I applied the before update event procedure.

I used a Cancel Event with Condition is Null and then Msgbox to warn then did a GotoRecord Next if condition is not null.

Works out well.

However the issue arises if I have a hidden form in the back. It doesn't pick up the active forms components.
Feb 18 '10 #3

Post your reply

Sign in to post your reply or Sign up for a free account.