Option Compare Database
Option Explicit
Private Sub cboFeeTypeID_AfterUpdate()
Dim iCount As Integer
iCount = DCount("*", "XLTWMInvoicing", "[Client Name] LIKE '* " & Me.cboClientID.Column(2) & " *'")
If Me.cboFeeTypeID.Column(1) = "Packs Fee" And iCount > 0 Then
MsgBox "Client Surname found in previous invoice. Please check not the same Client"
End If
Me.FeeAmount = Me.cboFeeTypeID.Column(2)
' Default the invoice date to the following Monday if empty
If IsNull(Me.InvoiceDate) Then
If (Me.FeeTypeID = 3 Or 4) Then
Me.InvoiceDate = DateAdd("d", 9 - Weekday(Date), Date)
Else
Me.InvoiceDate = Date
End If
End If
End Sub
Private Sub cmdClose_Click()
On Error GoTo ErrProc
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.Close
ExitProc:
Exit Sub
ErrProc:
Select Case Err.Number
Case 2101 ' save failed due to an error 2501 if not using me.dirty=false
MsgBox "Please fix error or close again", vbOKOnly
Resume ExitProc
Case 3021
Resume ExitProc
Case Else
MsgBox Err.Number & "--" & Err.Description
Resume ExitProc
End Select
End Sub
Private Sub cmdDelete_Click()
On Error GoTo ErrProc
DoCmd.RunCommand acCmdDeleteRecord
ExitProc:
Exit Sub
ErrProc:
Select Case Err.Number
Case 2501 'Delete cancelled message save failed due to an error 2501 if not using me.dirty=false
Resume ExitProc
Case Else
MsgBox Err.Number & "--" & Err.Description
Resume ExitProc
End Select
End Sub
Private Sub Form_AfterDelConfirm(Status As Integer)
Select Case Status
Case acDeleteOK
MsgBox "Record deleted!", , "Delete Result"
Case acDeleteCancel
MsgBox "Delete record cancelled!", , "Delete Result"
Case acDeleteUserCancel
MsgBox "Delete record cancelled!", , "Delete Result"
End Select
End Sub
Private Sub Form_BeforeDelConfirm(Cancel As Integer, Response As Integer)
Response = acDataErrContinue
' Display custom dialog box.
If MsgBox("Are you sure you want to delete this record?", vbYesNo, "Delete Confirmation") = vbNo Then
Cancel = True
End If
End Sub
Private Sub Form_BeforeInsert(Cancel As Integer)
If Me.NewRecord Then
Me.cboClientID = Me.OpenArgs
End If
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim blnError As Boolean
Dim strError As String, strResponse As String
On Error Resume Next
If Nz(Me.FeeAmount, 0) = 0 Then
blnError = True
strError = "Fee amount must be > £0" & vbCrLf
Me.FeeAmount.SetFocus
End If
If IsNull(Me.cboFeeTypeID) Then
blnError = True
strError = strError & "Fee Type is mandatory"
Me.cboFeeTypeID.SetFocus
End If
If blnError Then
Cancel = True
strResponse = MsgBox(strError, , "Data Validation")
End If
End Sub
Private Sub Form_Current()
' Protect controls if paid
Me.cboFeeTypeID.Enabled = IsNull(Me.PaidDate)
Me.FeeAmount.Enabled = IsNull(Me.PaidDate)
Me.InvoiceDate.Enabled = IsNull(Me.PaidDate)
Me.PaidDate.Enabled = IsNull(Me.PaidDate)
End Sub
Private Sub Form_Open(Cancel As Integer)
' This is the main form open event handler
'Me.RecordSource = "tblFee" 'set the recordsource of the main form
'Me.OrderBy = "Surname, Forenames"
'Me.OrderByOnLoad = True
'Me.OrderByOn = True
Me.cfrmFee.SourceObject = "cfrmFee" 'load datasheet subform w/ blank RecordSource
Set Me.cfrmFee.Form.Recordset = Me.Recordset 'set subform recordset to same object as main form's
End Sub