Results 1 to 2 of 2
2005-05-28, 01:31 #1
- Join Date
- Oct 2003
- Guelph, Ontario, Canada
- Thanked 0 Times in 0 Posts
Prevent Save of empty Invice (2000 all updates)
I have an Invoice form which contains basic information about the customer (the customer is a Camper in a campground). There are 2 subforms - one for service items, and the other for Credits.
Since this is a seasonal operation, a camper would not normally be invoiced twice for the same service. I therefore have put the following code on cboServices control on the services subform...
Private Sub cboService_AfterUpdate()
Dim txtTemp As Variant
Dim txtTemp2 As Variant
txtTemp = DLookup("[CamperID]", "qryTest", "[CamperID] = Forms!frmInvoice!CamperID AND [Service]=Forms!frmInvoice.Form!tblInvoiceDetails!cboServic e")
txtTemp2 = DMax("[InvoiceYear]", "qryTest")
If Not IsNull(txtTemp) And Year(Forms!frmInvoice!InvDate) = txtTemp2 Then
Select Case MsgBox("You already have this Service invoiced for" _
& vbCrLf & Forms!frmInvoice!CamperFirst & " " & Forms!frmInvoice!CamperLast & " for this Camping Year." _
& vbCrLf & " Is this a duplicate entry?" _
, vbYesNo Or vbExclamation Or vbDefaultButton1, "Possible duplicate service")
Call MsgBox("Thank you. The entry will be cancelled.", vbExclamation Or vbDefaultButton1, "Entry cancelled")
Call MsgBox("Thank you. Entry will be accepted." _
& vbCrLf & " Please continue." _
, vbExclamation Or vbDefaultButton1, "Entry accepted.")
Me.Rate = DLookup("[Rate]", "[tblRate]", "[RateID]=Forms!frmInvoice!tblInvoiceDetails.Form!cboServic e")
If the user enters a service, and gets the "possible duplicate" message and answers Yes, the entry is undone... but if this results in an empty invoice it should not be saved, so what I need is code which prevents the saving of an empty invoice.
On the Before Update event for the form itself, I have put the following code. Text16 and Text59 are totals for service and credit amounts. If both are $0.00 then the invoice should be completely undone and not saved. However this code does not do the job.
If Me.Dirty Then
If Me.Text16 = 0 And Me.Text59 = 0 Then
Call MsgBox("There are no entries in either Services or Credits." _
& vbCrLf & " Invoice will not be saved." _
, vbExclamation, "No Services or Credits")
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Any suggestions as to what I need further to add?
2005-05-29, 20:02 #2
- Join Date
- Aug 2001
- Evergreen, CO, USA
- Thanked 65 Times in 64 Posts
Re: Prevent Save of empty Invice (2000 all updates)
One method of cancelling the addition of a record is to use the Send Keys funtion to seen two ESC keys. This presumes that your form is bound - using a subform usually implies that. The end result is the same operation that you get if a user starts to add a record and then presses the Escape key twice, which cancels an add or edit process.
(Apologies for the delay in responses - many of us are away for the weekend.)Wendell