Customize error messay (1 Viewer)

odun

Registered User.
Local time
Today, 03:20
Joined
Apr 24, 2005
Messages
108
Hello all:

Thanks for all your numerous help.
I posted this earlier, but got no response, your urgent help is required.

I usually get 2 error messages on my form.

When I set up the table, I made the date field mandatory. The first error message, error 3314, "The field 'Memo.Date' cannot contain a Null value because the required property for this is se to True. Enter a value in this field"

I would like to change this error message to:
"Enter Date of Memo"



The second error is:
Microsoft Visual Basic
Run-time error '490':
Cannot open the specified file

End Debug buttons.

I would like to change this error message to:
"The file does not exist/it has not been previously saved."

And I don't want the End or Debug buttons to show.


Thanks for your help once again.
 

ghudson

Registered User.
Local time
Today, 06:20
Joined
Jun 8, 2002
Messages
6,195
You need to trap for those errors within your function or sub routines. You can not trap for errors in macros. You must trap for the errors within your forms. This example should get you going in the right direction...

Code:
Private Sub bDelete_Click()
On Error GoTo Err_bDelete_Click
    
    If MsgBox("Are you sure you want to delete the current user record for " & vbCrLf & tbUserID & " - " & tbFirstName & " " & tbLastName & "?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.RunCommand acCmdDeleteRecord
    End If

Exit_bDelete_Click:
    Exit Sub

Err_bDelete_Click:
    If Err.Number = 2046 Then 'The command DeleteRecord isn't available now - No records to delete
        MsgBox "There is no record to delete.", vbCritical, "Invalid Delete Request"
        Exit Sub
    ElseIf Err.Number = 2501 Then 'The RunCommand action was canceled
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bDelete_Click
    End If
    
End Sub
 

odun

Registered User.
Local time
Today, 03:20
Joined
Apr 24, 2005
Messages
108
Thanks, I am going to check this out now.
 

odun

Registered User.
Local time
Today, 03:20
Joined
Apr 24, 2005
Messages
108
Hi ghudson,

I forgot to ask where to put the code above.

I have a form C within a Form D.

In my form C, I have a date field that has to be entered.

When I click out of form C, I get the error 3314....cannot contain a null value.

So, where do I put this code you suggested that would customize the error, since I don't have a button or anything like that.

thanks for being patient.
 

ghudson

Registered User.
Local time
Today, 06:20
Joined
Jun 8, 2002
Messages
6,195
The forms Before Update event is the key to data validation at the form level.

You should also protect the users [and the data]. I suggest you look at these two threads and see how I control what a user can do and how I force them to either save or undo their changes before they can save the record or close the form. Check these links out for more info and samples...

A Better Mouse Trap?

Enable/Disable The Control Box X Button

Use the IsNull() function to test if a field is Null [empty].
Code:
If IsNull([YourTextbox1]) or [YourTextbox1] = "" Then
     Msgbox "YourTextbox1 is Null"
Else
     Msgbox "YourTextbox1 is not Null"
End If
 
Last edited:

Users who are viewing this thread

Top Bottom