Wrox Home  
Search P2P Archive for: Go

  Return to Index  

access thread: form_error event


Message #1 by rachel.chappell@B... on Thu, 19 Dec 2002 09:18:25
Hi

I have a table in the following format

ID		-autonumber
VendorName	-required no duplicates


I have a data entry form for the user to add new vendors. As the VendorName
is set to 'no duplicates' I get an Access generated error stating  'the 
table was not updated as this would create duplicate indexes'  (Error 
3022) if I try to add a duplicate record.
I would like to be able to trap this error and write a more user friendly 
one. I can trap the error using the form_error event and this appears to 
be triggered by the user clicking on the standard close button (top RHS)  
or by moving to a new record using the standard navigation buttons.

However I would like to remove the standard close button and navigation 
bar from the form. 
If the errror occurs I would like to continue to display the form and give 
the 
user another chance to enter a VendorName.

Does any one know the best way to trap / trigger the form_error 
event.      

Thanks

Rachel 
Message #2 by "Enzo Zaragoza" <enzaux@g...> on Thu, 19 Dec 2002 17:51:41 +0800
On your Save button:

	On Error Goto Err_Save
         .
         . your codes for saving
         .
       Exit_Save:
          Exit Sub
       Err_Save:
          MsgBox "Vendor Name already taken!", vbExclamation + vbOkOnly, "Save Error"
          txtVendorName.Setfocus
          Resume Exit_Save


enzo c",)?
http://www.tropangwatakwatak.tk

-----Original Message-----
From: rachel.chappell@B... [mailto:rachel.chappell@B...]
Sent: Thursday, December 19, 2002 9:18 AM
To: Access
Subject: [access] form_error event


Hi

I have a table in the following format

ID		-autonumber
VendorName	-required no duplicates


I have a data entry form for the user to add new vendors. As the VendorName
is set to 'no duplicates' I get an Access generated error stating  'the
table was not updated as this would create duplicate indexes'  (Error
3022) if I try to add a duplicate record.
I would like to be able to trap this error and write a more user friendly
one. I can trap the error using the form_error event and this appears to
be triggered by the user clicking on the standard close button (top RHS)
or by moving to a new record using the standard navigation buttons.

However I would like to remove the standard close button and navigation
bar from the form.
If the errror occurs I would like to continue to display the form and give
the
user another chance to enter a VendorName.

Does any one know the best way to trap / trigger the form_error
event.

Thanks

Rachel



Message #3 by "Gregory Serrano" <SerranoG@m...> on Thu, 19 Dec 2002 13:06:45
Rachel,

<< I have a data entry form for the user to add new vendors. As the 
VendorName is set to 'no duplicates' I get an Access generated error 
stating  'the table was not updated as this would create duplicate 
indexes'  (Error 3022) if I try to add a duplicate record.

I would like to be able to trap this error and write a more user friendly 
one.>>

Put this code on your form's "After Update" event.

   Private Sub Form_AfterUpdate()

      On Error GoTo Err_Form_AfterUpdate

      'Whatever else you need goes here or leave blank.
    
      Exit_Form_AfterUpdate:
         Exit Sub

      Err_Form_AfterUpdate:
         Select Case Err.Number
            Case 3022
               MsgBox "This vendor name already exists.", vbExclamation, _
               "Duplicate Vendor Name!"
            Case ...
               'Whatever other error number you wish to trap...
            Case Else
               MsgBox Err.Description, vbExclamation, "Error " & Err.Number
         End Select
         Resume Exit_Form_AfterUpdate
   
   End Sub


Greg
Message #4 by "Bob Bedell" <bobbedell15@m...> on Thu, 19 Dec 2002 12:58:39 +0000
Hi Rachel,

Something like the following should work:

Private Sub Form_Error(DataErr As Integer, Response As Integer)
  Dim strMsg As String

  If DataErr = 3022
    strMsg = "This record contains the same" & vbCrLf
    strMsg = strMsg & "Vendor Name as another record" & vbCrLf & vbCrLf
    strMsg = strMsg & "Changes were unsuccessful."

    MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
      vbCritical + vbOKOnly, "Duplicate Vendor Name."

    Me.txtVendorName.Text = ""
    Me.txtVendorName.SetFocus
    Response = acDataErrContinue
  Else
    Response = acDataErrDisplay
  End If

End Sub


You don't have to worry about triggering the Error event. It will fire
anytime an error occurs while Access is making calls to the database
engine. In your case, it will fire the moment txtVendorName looses the
focus with the duplicate value in it.

Don't forget to be sure that [Event Procedure] appears in the forms On
Error property.

Best,

Bob



>From: rachel.chappell@B...
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] form_error event
>Date: Thu, 19 Dec 2002 09:18:25
>
>Hi
>
>I have a table in the following format
>
>ID		-autonumber
>VendorName	-required no duplicates
>
>
>I have a data entry form for the user to add new vendors. As the VendorName
>is set to 'no duplicates' I get an Access generated error stating  'the
>table was not updated as this would create duplicate indexes'  (Error
>3022) if I try to add a duplicate record.
>I would like to be able to trap this error and write a more user friendly
>one. I can trap the error using the form_error event and this appears to
>be triggered by the user clicking on the standard close button (top RHS)
>or by moving to a new record using the standard navigation buttons.
>
>However I would like to remove the standard close button and navigation
>bar from the form.
>If the errror occurs I would like to continue to display the form and give
>the
>user another chance to enter a VendorName.
>
>Does any one know the best way to trap / trigger the form_error
>event.
>
>Thanks
>
>Rachel


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

Message #5 by "Bob Bedell" <bobbedell15@m...> on Thu, 19 Dec 2002 14:14:05 +0000
>In your case, it will fire the moment txtVendorName looses the focus with 
>the duplicate value in it.

Sorry Rachel...got that bit wrong. The Error event will fire in your
case when you try and save the record with the duplicate value in it,
however you attempt to do that. I confused myself by only having a
txtVendorName on my form. When I tabbed out of the textbox, the Error
event fired, not however because txtVendorName lost the focus, but
because it was the last control on the form, and Access was attempting
to save the record.

Also, you need to flip two lines of code. I wrote:

Me.txtVendorName.Text = ""
Me.txtVendorName.SetFocus

You need:

Me.txtVendorName.SetFocus
Me.txtVendorName.Text = ""

The Text property is unavailable unless a control has the focus.

Should work for you now.


>From: "Bob Bedell" <bobbedell15@m...>
>Reply-To: "Access" <access@p...>
>To: "Access" <access@p...>
>Subject: [access] Re: form_error event
>Date: Thu, 19 Dec 2002 12:58:39 +0000
>
>Hi Rachel,
>
>Something like the following should work:
>
>Private Sub Form_Error(DataErr As Integer, Response As Integer)
>  Dim strMsg As String
>
>  If DataErr = 3022
>    strMsg = "This record contains the same" & vbCrLf
>    strMsg = strMsg & "Vendor Name as another record" & vbCrLf & vbCrLf
>    strMsg = strMsg & "Changes were unsuccessful."
>
>    MsgBox "Error Number: " & DataErr & vbCrLf & vbCrLf & strMsg, _
>      vbCritical + vbOKOnly, "Duplicate Vendor Name."
>
>    Me.txtVendorName.Text = ""
>    Me.txtVendorName.SetFocus
>    Response = acDataErrContinue
>  Else
>    Response = acDataErrDisplay
>  End If
>
>End Sub
>
>
>You don't have to worry about triggering the Error event. It will fire
>anytime an error occurs while Access is making calls to the database
>engine. In your case, it will fire the moment txtVendorName looses the
>focus with the duplicate value in it.
>
>Don't forget to be sure that [Event Procedure] appears in the forms On
>Error property.
>
>Best,
>
>Bob
>
>
>
>>From: rachel.chappell@B...
>>Reply-To: "Access" <access@p...>
>>To: "Access" <access@p...>
>>Subject: [access] form_error event
>>Date: Thu, 19 Dec 2002 09:18:25
>>
>>Hi
>>
>>I have a table in the following format
>>
>>ID		-autonumber
>>VendorName	-required no duplicates
>>
>>
>>I have a data entry form for the user to add new vendors. As the 
>>VendorName
>>is set to 'no duplicates' I get an Access generated error stating  'the
>>table was not updated as this would create duplicate indexes'  (Error
>>3022) if I try to add a duplicate record.
>>I would like to be able to trap this error and write a more user friendly
>>one. I can trap the error using the form_error event and this appears to
>>be triggered by the user clicking on the standard close button (top RHS)
>>or by moving to a new record using the standard navigation buttons.
>>
>>However I would like to remove the standard close button and navigation
>>bar from the form.
>>If the errror occurs I would like to continue to display the form and give
>>the
>>user another chance to enter a VendorName.
>>
>>Does any one know the best way to trap / trigger the form_error
>>event.
>>
>>Thanks
>>
>>Rachel
>
>
>_________________________________________________________________
>Tired of spam? Get advanced junk mail protection with MSN 8. 
>http://join.msn.com/?page=features/junkmail
>
>
>---
>Change your mail options at http://p2p.wrox.com/manager.asp or to 
>unsubscribe send a blank email to 


_________________________________________________________________
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail


  Return to Index