Results 1 to 3 of 3
  1. #1
    4 Star Lounger
    Join Date
    May 2003
    Location
    Manchester, Gtr Manchester, England
    Posts
    552
    Thanks
    0
    Thanked 0 Times in 0 Posts

    system messages (2000)

    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.
    .

  2. #2
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    San Francisco, California, USA
    Posts
    358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: system messages (2000)

    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

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: system messages (2000)

    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

Posting Permissions

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