Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2004
    Posts
    110

    Unanswered: Navigator bar error

    Hello everybody

    I have built a form bounded to a table. There exists a navigation toolbar on the form. The problem is that sometimes a user may not complete all fields on a form, yet try to press the next record button on the navigator toolbar. The result is usually a run-time error, since it might happen that the unfilled fields is part of a primary key or otherwise required.
    I have thought of using the BeforeUpdate() function of a form. But, I don`t know how to go about this. What sort of error am I supposed to check? I would like Access not to move to another record unless the previous one has been commited successfully to the disc.

    thx, in advance

    George Papadopoulos
    Attached Thumbnails Attached Thumbnails flip-lid.gif  

  2. #2
    Join Date
    Mar 2004
    Posts
    118
    There is a way to turn off error messages.

    DoCmd.SetWarnings False

    on form_open

    But, im not sure if that will help you.


    Do you want the form NOT to update when you browse records? I'm not sure if thats possible.

  3. #3
    Join Date
    Mar 2004
    Posts
    33

    Navigator Bar Error

    What you might think about doing is create a procedure that validates the required fields before processing the GoToNext, Last, New, etc.. using the Dirty property.

    This is a sample of the code I use in the OnClick Event of the GoToNext button.

    Private Sub btnGoToNext_Click()
    On Error GoTo Err_btnGoToNext_Click
    If Me.Dirty = True Then
    DataValidation 'Places call to data validation procedure
    Exit Sub
    Else
    DoCmd.GoToRecord , , acNext
    End If
    Exit_btnGoToNext_Click:
    Exit Sub

    Err_btnGoToNext_Click:
    MsgBox Err.Description
    Resume Exit_btnGoToNext_Click

    End Sub

    Private Sub DataValidation()
    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++
    '+ Error Trapping +
    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++


    Dim MsgText, MsgStyle, MsgTitle, MsgHelp, MsgCtxt, MsgResponse, MsgDefault 'Variable Names
    Dim Err_Trap, ErrorMsg
    MsgStyle = vbOKOnly + vbInformation
    MsgTitle = "Data Validation Error"
    MsgDefault = "Check your data and try again."
    'MsgHelp is the name of the help file
    'MsgCtxt is the name of the help file context number
    'Err_Trap = 'Variable value will need to be reset for each error test


    If IsNull([cbo_ApplyDate]) Then
    MsgText = "There is no data in the Apply Date field. " & Chr(13) & Chr(13) & MsgDefault
    MsgResponse = MsgBox(MsgText, MsgStyle, MsgTitle)
    Me.cbo_ApplyDate.SetFocus
    Else
    GoTo ApplyDateError
    End If

    ApplyDateError:
    Err_Trap = Me.cbo_ApplyDate.Value
    Select Case Err_Trap
    Case Is > cbo_HireDate
    MsgText = "The Hire Date cannot be before the Apply Date." & vbCr & "Please check your data and try again."
    ErrorMsg = MsgBox(MsgTxt, MsgStyle, MsgTitle)
    cbo_ApplyDate.SetFocus
    Exit Sub
    Case Is > Date
    MsgTxt = "The Apply Date cannot be greater than the current date." & vbCr & "Please check your data and try again."
    ErrorMsg = MsgBox(MsgTxt, MsgStyle, MsgTitle)
    cbo_ApplyDate.SetFocus
    Exit Sub
    Case Is = cbo_HireDate
    MsgResponse = MsgBox("The Apply Date and Hire Date are the same. Are you sure that you want to continue?" _
    , vbYesNo, "Data Validation Error")
    If MsgResponse = vbYes Then
    DoCmd.GoToRecord , , acNext
    Exit Sub
    ElseIf MsgResponse = vbNo Then
    cbo_ApplyDate.SetFocus
    Exit Sub
    End If
    Case Else
    GoTo HiredDateError
    End Select

    HiredDateError:
    Err_Trap = Me.Hired.Value
    MsgBox "Define the Hired Date Errors Here"
    Exit Sub

    End Sub


    Hope this helps.

  4. #4
    Join Date
    Mar 2004
    Posts
    33
    My apologies to all. I posted before I should have. I have an undeclared variable in the previously posted code for the DataValidaton procedure.

    The correct code is as follows:


    Private Sub DataValidation()
    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++
    '+ Error Trapping +
    '+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++


    Dim MsgText, MsgStyle, MsgTitle, MsgHelp, MsgCtxt, MsgResponse, MsgDefault 'Variable Names
    Dim Err_Trap, ErrorMsg
    MsgStyle = vbOKOnly + vbInformation
    MsgTitle = "Data Validation Error"
    MsgDefault = "Check your data and try again."
    'MsgHelp is the name of the help file
    'MsgCtxt is the name of the help file context number
    'Err_Trap = 'Variable value will need to be reset for each error test

    'MAY NEED TO CHECK FOR NULLS IN ANY REQUIRED FIELD BEFORE TESTING DATA

    If IsNull([cbo_ApplyDate]) Then
    MsgText = "There is no data in the Apply Date field. " & Chr(13) & Chr(13) & MsgDefault
    MsgResponse = MsgBox(MsgText, MsgStyle, MsgTitle)
    Me.cbo_ApplyDate.SetFocus
    Else
    GoTo ApplyDateError
    End If

    ApplyDateError:
    Err_Trap = Me.cbo_ApplyDate.Value
    Select Case Err_Trap
    Case Is > cbo_HireDate
    MsgText = "The Hire Date cannot be before the Apply Date." & vbCr & "Please check your data and try again."
    ErrorMsg = MsgBox(MsgText, MsgStyle, MsgTitle)
    cbo_ApplyDate.SetFocus
    Exit Sub
    Case Is > Date
    MsgText = "The Apply Date cannot be greater than the current date." & vbCr & "Please check your data and try again."
    ErrorMsg = MsgBox(MsgText, MsgStyle, MsgTitle)
    cbo_ApplyDate.SetFocus
    Exit Sub
    Case Is = cbo_HireDate
    MsgResponse = MsgBox("The Apply Date and Hire Date are the same. Are you sure that you want to continue?" _
    , vbYesNo, "Data Validation Error")
    If MsgResponse = vbYes Then
    DoCmd.GoToRecord , , acNext
    Exit Sub
    ElseIf MsgResponse = vbNo Then
    cbo_ApplyDate.SetFocus
    Exit Sub
    End If
    Case Else
    GoTo HiredDateError
    End Select

    HiredDateError:
    Err_Trap = Me.Hired.Value
    MsgBox "Define the Hired Date Errors Here"
    Exit Sub

    End Sub



    Thanks

Posting Permissions

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