• system messages (2000)

    Author
    Topic
    #394750

    How can I change system message boxes to display a more meaningful message to my users. EG when data is deleted from a record leaving null, the system message about there not being able to be null values in primary fields shows, how can I modify what is shown and as such direct my users with a message in plain English?

    Thanks Darren.
    .

    Viewing 3 reply threads
    Author
    Replies
    • #726117

      What I would do is verify the data as the user enters it (ie. use the BeforeUpdate event). You can verify just about anything that way.

      For example,

      Sub txtMyTextBox_BeforeUpdate(Cancel As Integer)

      If me.txtMyTextBox=”” Then
      MsgBox “You can’t leave this field blank!”
      me.txtMyTextBox.setfocus

      End Sub

    • #726118

      What I would do is verify the data as the user enters it (ie. use the BeforeUpdate event). You can verify just about anything that way.

      For example,

      Sub txtMyTextBox_BeforeUpdate(Cancel As Integer)

      If me.txtMyTextBox=”” Then
      MsgBox “You can’t leave this field blank!”
      me.txtMyTextBox.setfocus

      End Sub

    • #726127

      Cecilia’s suggestion will work well.

      Another method is to trap errors at the form level, by writing code in the On Error event of the form. (There are no events at the table or query level in Access, but in a serious database you won’t let users edit data in a table or query anyway, so that doesn’t matter.)

      The event procedure for the On Error event has two arguments: DataErr and Response. DataErr is the error number, you can inspect it to decide on your reaction. While you are developing, it’s best to start by reporting this error number and the corresponding error message:

      Private Sub Form_Error(DataErr As Integer, Response As Integer)
      MsgBox “Error no ” & DataErr & ” occurred, with message:” & vbCrLf & _
      AccessError(DataErr)
      End Sub

      AccessError(n) returns the text of the standard error message corresponding to error number n.

      Each time an error occurs, write down the error number. For the final version, you can handle individual errors by using a Select Case … End Select block.

      Response determines how the error is handled. Its default value is acDataErrDisplay, meaning that Access displays the standard error message. You can set it to acDataErrContinue to tell Access that the error has been handled or can be ignored; this suppresses the standard error message.

      Private Sub Form_Error(DataErr As Integer, Response As Integer)
      Select Case DataErr
      Case 2501
      ‘ Action canceled by user – ignore and don’t show message
      Response = acDataErrContinue
      Case 2165
      ‘ Can’t set focus to invisible control
      MsgBox “The programmer of this database tried to set focus to an invisible control. Bad! Bad!”
      Response = acDataErrContinue
      Case …

      Case Else
      ‘ Everything else; let Access handle it
      Response = acDataErrDisplay
      End Select
      End Sub

    • #726128

      Cecilia’s suggestion will work well.

      Another method is to trap errors at the form level, by writing code in the On Error event of the form. (There are no events at the table or query level in Access, but in a serious database you won’t let users edit data in a table or query anyway, so that doesn’t matter.)

      The event procedure for the On Error event has two arguments: DataErr and Response. DataErr is the error number, you can inspect it to decide on your reaction. While you are developing, it’s best to start by reporting this error number and the corresponding error message:

      Private Sub Form_Error(DataErr As Integer, Response As Integer)
      MsgBox “Error no ” & DataErr & ” occurred, with message:” & vbCrLf & _
      AccessError(DataErr)
      End Sub

      AccessError(n) returns the text of the standard error message corresponding to error number n.

      Each time an error occurs, write down the error number. For the final version, you can handle individual errors by using a Select Case … End Select block.

      Response determines how the error is handled. Its default value is acDataErrDisplay, meaning that Access displays the standard error message. You can set it to acDataErrContinue to tell Access that the error has been handled or can be ignored; this suppresses the standard error message.

      Private Sub Form_Error(DataErr As Integer, Response As Integer)
      Select Case DataErr
      Case 2501
      ‘ Action canceled by user – ignore and don’t show message
      Response = acDataErrContinue
      Case 2165
      ‘ Can’t set focus to invisible control
      MsgBox “The programmer of this database tried to set focus to an invisible control. Bad! Bad!”
      Response = acDataErrContinue
      Case …

      Case Else
      ‘ Everything else; let Access handle it
      Response = acDataErrDisplay
      End Select
      End Sub

    Viewing 3 reply threads
    Reply To: system messages (2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: