Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    173

    Unanswered: Validation Problem on Cancel Event

    I am using the code below in the BeforeUpdate Event of a Form.
    I want to be sure the User fills in the Required Fields.


    If the User tries to Save a Record it Traps the Events, and opens the message box I have set - but I also get a message saying "You Cancelled the Previous Operation"

    How can I do this without getting the "You Cancelled the Previous Operation" message? I tried Cancel = True, but got a different message.

    If I put the same code in the OnClick Event of the Save button I do not get the "You Cancelled the Previous Operation" message....





    If Me.Category = "" Then
    MsgBox "Enter a Category"
    Me.Category.SetFocus
    DoCmd.CancelEvent
    ElseIf Me.StockNumber = "" Then
    MsgBox "Enter a Stock Number"
    Me.StockNumber.SetFocus
    DoCmd.CancelEvent
    ElseIf Me.Description = "" Then
    MsgBox "Enter a Description"
    Me.Description.SetFocus
    DoCmd.CancelEvent
    ElseIf Me.Unit = "" Then
    MsgBox "Enter a Unit"
    Me.Unit.SetFocus
    DoCmd.CancelEvent
    End If

  2. #2
    Join Date
    May 2003
    Posts
    144
    Try to have the following script under the Save Record Button --

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdUndo
    DoCmd.SetWarnings True

    Hope this helps

    SHK

  3. #3
    Join Date
    Jan 2005
    Posts
    1
    You don't get the message box if you put the code in the save button, because the save button doesn't have a cancel as integer parameter. So, it might be best to put it under the save button. Ie,


    Dim field As String
    If IsNull(Category.Value) = True Then
    field = "a category"
    Category.SetFocus
    ElseIf IsNull(StockNumber.Value) = True Then
    field = "a stock number"
    StockNumber.SetFocus
    Else if IsNull(Description.Value) = True Then
    field = "a Description"
    Description.SetFocus

    End If
    If IsNull(Description.Value) = True Or (IsNull(StockNumber.Value) = True Or IsNull(Category.Value) = True) Then
    MsgBox "You must enter " & field, vbOKOnly, "Data integrity is important"
    Goto Finish
    End If

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Finish:

  4. #4
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    If you are using the BeforeUpdate event then why no use the Cancel agument of the event and just say

    Cancel= True (in place DoCmd.CancelEvent)

    This will cancel the update and (I believe) will not produce a message.

    Also can't you uae Me.Undo in place of DoCmd.RunCommand acCmdUndo ?

    Just a thought.


    MTB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •