Results 1 to 3 of 3

Thread: Validation Rule

  1. #1
    Join Date
    Apr 2009
    Posts
    85

    Unanswered: Validation Rule

    I have a validation rule set up before my form is printed and saved, the rule works fine but once the msg box shows up saying please make a choice for xyz
    the routine just powers through and dose not wait for a choice to be made, can anyone tell me how to make the routine pause for the choice to be made then continue







    On Error GoTo Err_Command101_Click
    Dim msg As String, Style As Integer, Title As String
    Dim nl As String, ctl As Control


    nl = vbNewLine & vbNewLine

    For Each ctl In Me.Controls
    If ctl.ControlType = acTextBox Then
    If ctl.Tag = "*" And Trim(ctl & "") = "" Then
    msg = "Data Required for '" & ctl.Name & "' field!" & nl & "Required Data!" & nl & "Please enter the data and try again ... "
    Style = vbOKOnly
    Title = "Required Data..."
    MsgBox msg, Style, Title
    ctl.SetFocus
    Cancel = True
    Exit For
    End If
    End If
    If ctl.ControlType = acComboBox Then
    If ctl.Tag = "c" And ctl.ListIndex = -1 Then
    MsgBox "Please Enter Evaluator Name."
    ctl.SetFocus
    Cancel = True
    Exit For
    End If
    End If
    Next

    PAUSE HERE
    Me.AssetID.SetFocus
    Me.Command110.Visible = False
    Me.Close_Form.Visible = False
    Me.Command119.Visible = False
    Me.Command101.Visible = False

    DoCmd.PrintOut
    DoCmd.GoToRecord , , acNewRec

    Me.Command110.Visible = True
    Me.Close_Form.Visible = True
    Me.Command119.Visible = True
    Me.Command101.Visible = True
    Me.Command101.SetFocus

    Exit_Command101_Click:
    Exit Sub

    Err_Command101_Click:
    MsgBox Err.Description
    Resume Exit_Command101_Click

  2. #2
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    If you need the user to add something to the form, you need to completely halt the execution of the code. The Click event doesn't have a Cancel argument (you can't stop it happening once the user has released the command button), so replace
    Code:
    Cancel = True
    with
    Code:
    Exit Sub
    The user will then have to enter a value in the selected control and click the button again.

    They might not like it, but it does the trick!

  3. #3
    Join Date
    Apr 2009
    Posts
    85
    Thanks weejus

Posting Permissions

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