olorin
Registered User.
- Local time
- Today, 08:06
- Joined
- Jun 9, 2006
- Messages
- 81
I am by no means an expert on VBA, and have only got as far as I have with VBA by viewing the excellent tips and examples in this forum.
That said, I am stuck on Error Trapping.
I have a form with it's datasource tblInvoices.
It automatically fills in a couple of required fields when opened with data from a related from which is open in the background.
In the tblInvoices, the field "InvoiceNumber" is indexed with NoDuplicates allowed, (it is NOT the primary key).
I have tried to include an error trap on the form, for when someone enters an Invoice number that has already been used.
This is what I have;
When the user enters an Invoice Number that has already been used, it tells them after they exit the "Notes" field.
It also clears the record and sets the focus back to the Invoice Number field.
After entering in new information it keep coming back to the "Err_SameNumber" routine and will not let me out.
I have to use the Windows Task Manager to exit the program.
If anyone can throw any light on this and point out my error I would be grateful
Thank you
That said, I am stuck on Error Trapping.
I have a form with it's datasource tblInvoices.
It automatically fills in a couple of required fields when opened with data from a related from which is open in the background.
In the tblInvoices, the field "InvoiceNumber" is indexed with NoDuplicates allowed, (it is NOT the primary key).
I have tried to include an error trap on the form, for when someone enters an Invoice number that has already been used.
This is what I have;
Code:
Private Sub Notes_Exit(Cancel As Integer)
On Error GoTo Err_SameNumber
Dim iResponse As Integer
iResponse = MsgBox("Do you wish to Print an Invoice", vbYesNo, "SELECT AN OPTION")
If iResponse = vbYes Then
DoCmd.RunCommand acCmdSaveRecord
Forms!frmSelectInvoice!Invoiced.Value = True
Forms!frmSelectInvoice.Requery
DoCmd.Save acForm, "frmInvoice"
DoCmd.OpenReport "rptInvoice", acNormal, "", "[pkInvoiceID]=[Forms]![frmInvoice]![pkInvoiceID]"
Me.btnClose.SetFocus
Exit Sub
End If
If iResponse = vbNo Then
MsgBox "You can Print it out later from the Invoices Main Menu", , "You Selected NO"
End If
DoCmd.RunCommand acCmdSaveRecord
Forms!frmSelectInvoice!Invoiced.Value = True
Forms!frmSelectInvoice.Requery
Me.btnClose.SetFocus
Exit_SameNumber:
DoCmd.RunCommand acCmdUndo
DoCmd.GoToRecord , , acNewRec
Me.fkBookingID.Value = Forms!frmSelectInvoice!pkBookingID.Value
Me.fkCustomerID.Value = Forms!frmSelectInvoice!fkCustomerID.Value
Me.InvoiceNumber.SetFocus
Exit Sub
Err_SameNumber:
MsgBox "Invoice Number has already been used", vbInformation, "Please use a New Invoice Number"
Resume Exit_SameNumber
End Sub
When the user enters an Invoice Number that has already been used, it tells them after they exit the "Notes" field.
It also clears the record and sets the focus back to the Invoice Number field.
After entering in new information it keep coming back to the "Err_SameNumber" routine and will not let me out.
I have to use the Windows Task Manager to exit the program.
If anyone can throw any light on this and point out my error I would be grateful
Thank you