Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to disable access errors messages

Status
Not open for further replies.

shelron

Technical User
Apr 9, 2002
135
US
access 2002,

tblAddBook (1) To tblContacts (many)
add_id Primary key add_id foreign key

referential integrity with cascade



I have a main form (frmAssignContactToProject) that allows users to enter a new person, then on the subform (datasource is tblContacts) they can add many projects.

The error that is occuring is this, I have a cmd button that creates a new record. If the user starts on the many side (on the subform) access error pops up because it cannot find a matching record in tblAddbook. Also, it locks up the database and the user cannot exit without ctraltdelte.

My code below attempts to evaluate if the add_id is null, then send the user back to the main form, It seems to run okay, but I keep getting the access error message.

I THINK? that if I can disable the access message, run my code, then enable the access messages, it will run???

Have I got a clue??

Thanks for any help, Ron






Private Sub Form_Dirty(Cancel As Integer)

'deal with access error message,
'if user tries to create a record on the many side, of addbook to contacts
'notify user to start record with person rather than project,
'then set focus to the main form

If Me.tblAddBook_ADD_ID = Null Then

MsgBox "Please begin data entry with the Contact Information, then you may assign a project."
frmAssignContactToProject.FIRM_NAME.SetFocus

End If
End Sub
 
Hi. Use Error Traping to deal with this. You need to know the error codes. See Access Help. Hope it helps

Private Sub Form_Dirty(Cancel As Integer)

on error goto ErrorDirty:

'deal with access error message,
'if user tries to create a record on the many side, of addbook to contacts
'notify user to start record with person rather than project,
'then set focus to the main form

If Me.tblAddBook_ADD_ID = Null Then

MsgBox "Please begin data entry with the Contact Information, then you may assign a project."
frmAssignContactToProject.FIRM_NAME.SetFocus

ErrorDirty:
If Err = xxxx then
'Do Something
Else If Err = xxxx
'Do Something Else
Else
'
End If

End If
End Sub Best Regards

---
JoaoTL
mail@jtl.co.pt
My MS Access Site:
 
Thanks for the direction, I have tried the following, no change, I still get the same messages.

Ron





Private Sub Form_Dirty(Cancel As Integer)

On Error GoTo ErrorDirty:

'deal with access error message,
'if user tries to create a record on the many side, of addbook to contacts
'notify user to start record with person rather than project,
'then set focus to the main form

If Me.tblAddBook_ADD_ID = Null Then

MsgBox "Please begin data entry with the Contact Information, then you may assign a project."
frmAssignContactToProject.FIRM_NAME.SetFocus
End If

ErrorDirty:
If Err = 3162 Then
DoCmd.SetWarnings False
Resume

If Err = 3101 Then
DoCmd.SetWarnings False
Resume

End If






End If

End Sub
 
Another thought,

Do I need to clear out the new record before trying to shift focus back to the main form?

Ron
 
Try like this

Private Sub Form_Dirty(Cancel As Integer)

On Error GoTo ErrorDirty:

'deal with access error message,
'if user tries to create a record on the many side, of addbook to contacts
'notify user to start record with person rather than project,
'then set focus to the main form

If Me.tblAddBook_ADD_ID = Null Then

MsgBox "Please begin data entry with the Contact Information, then you may assign a project."
frmAssignContactToProject.FIRM_NAME.SetFocus
End If

ErrorDirty:
If Err = 3162 Then
MsgBox"You Need to Create that Code in The XX Table"
exit sub
else if Err = 3101 Then
MsgBox"You Need to Create that Code in The XX Table"
exit sub
End If
Best Regards

---
JoaoTL
mail@jtl.co.pt
Take a Look in my VBA Section:
 
I appreciate your help, but I still get the exact same system errors, and once that happens everything locks up, there is no way to exit, it just loops.

This is the code I pasted.

Private Sub Form_Dirty(Cancel As Integer)

On Error GoTo ErrorDirty:

'deal with access error message,
'if user tries to create a record on the many side, of addbook to contacts
'notify user to start record with person rather than project,
'then set focus to the main form

If Me.tblAddBook_ADD_ID = Null Then

MsgBox "Please begin data entry with the Contact Information, then you may assign a project."
frmAssignContactToProject.FIRM_NAME.SetFocus
End If

ErrorDirty:
If Err = 3162 Then
MsgBox "You Need to Create that Code in The XX Table"
Exit Sub
ElseIf Err = 3101 Then
MsgBox "You Need to Create that Code in The XX Table"
Exit Sub
End If
 
Humm..Ok Sorry about that

But why are you using the On_Dirty Event????

Try this

Were you open the Form

DoCmd.OpenForm("xxxx")
DoCmd.SetWarnings False

On The On_Close Event put
DoCmd.SetWarnings True Best Regards

---
JoaoTL
mail@jtl.co.pt
Take a Look in my VBA Section:
 
I was using the on dirty event to try to get ahead of the after update.

I already tried the docmd.setwarnings false on the load event.

still no change.

I am pretty new at this but it seems that if the user has created a new record on the many side, then the systems sends a message that referential integrity is violated (no corresponding record in the one table), in order to exit that, shouldn't I have to delete the current record??

I'm stumped.

thanks, ron
 
You are not using the Correct Error Code in the Error Traping. The Error Code is 3201. I Tested your sub and it Worked just Fine.

This error happen when you have a Code in the Main Table that is not in the related Table. Best Regards

---
JoaoTL
mail@jtl.co.pt
Take a Look in my VBA Section:
 
When the error occurs, selecting help gives me the error numbers I have used. I tried using 3201 instead of 3101 but it still doesn't work.

Evidently, I must have something else happening.

Thanks for all your help, I'll continue to look into it, If I find the problem, I'll post it back,

thanks ron
 
Just a quick thought before I leave for home..would it be better to run the code with the event BeforeUpdate, rather than AfterUpdate?
 
I have tried it that way,

My logic is this,

The before update wouldn't be triggered after a user enters data,

that's why I was trying to use the dirty because if the record is dirty, and the foreign key is null, then they started entering on the many side of a one to many,,


hmmmmmmm, I wonder if I could tackle this another way, by perhaps by hiding the subform until a new record is created in the main form,
'

hmmmmmmmmmm, I gonna look into that type of possiblity,

thanks again, ron
 
BeforeUpdate allows the data entry to take place..but runs the code before the actual record in the table is updated, giving you the chance to check it and cancel the update. Anyway..lift is waiting..I'll try something tomorrow if you've had no luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top