Require Selection in Combo before Running a Save Macro.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ilikebirds
    New Member
    • Oct 2007
    • 36

    Require Selection in Combo before Running a Save Macro.

    I would like all combo boxes to have require data before the following macro is run from a button:
    Code:
    Private Sub Command128_Click()
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString
    Msg = "Please Verify Work Stream and Process"   ' Define message.
    Style = vbYesNo + vbInformation + vbDefaultButton2   ' Define buttons.
    Title = "Verify Data"   ' Define title.
    Help = "DEMO.HLP"   ' Define Help file.
    Ctxt = 1000   ' Define topic
          ' context.
          ' Display message.
    Response = MsgBox(Msg, Style, Title, Help, Ctxt)
    If Response = vbYes Then   ' User chose Yes.
       DoCmd.RunMacro ("Save")  ' Perform some action.
    Else   ' User chose No.
       MyString = "No"   ' Perform some action.
    End If
    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.
  • Stewart Ross
    Recognized Expert Moderator Specialist
    • Feb 2008
    • 2545

    #2
    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).

    -Stewart

    Comment

    • ilikebirds
      New Member
      • Oct 2007
      • 36

      #3
      Before Update

      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.

      Comment

      Working...