Option Compare Database
Option Explicit
' Declare an instance of our class
Private CF As clsConditionalFormatting
Private Sub testAddAppt()
On Error GoTo err_handler
If (Not Me.cbIncoming = 0 Or Not Me.cbOutgoing = 0) And Not Me.cobCarrier.Value = "" Then
If Not strGroupPolicy = "Users - View Only" Then DoCmd.RunCommand acCmdSaveRecord
End If
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub TestAppt(ByVal Cancel As Integer)
If (Not Me.cbIncoming = 0 Or Not Me.cbOutgoing = 0) And Not Me.cobCarrier.Value = "" Then
If IsNull(Me.tbArrDate) And Not IsNull(Me.tbArrTime) Then Me.tbArrDate.Value = Date
If IsNull(Me.tbDate.Value) Then Me.tbDate.Value = Form.frmscheduled_appts.cldrApptDates.Value
If Me.Dirty Then Me.tbModifiedby.Value = strUserLogin
If Me.Dirty Then Me.tbModifiedDate.Value = Date
If IsNull(Me.tbCreatedBy.Value) Then Me.tbCreatedBy.Value = strUserLogin
If IsNull(Me.Confirmation_Num.Value) Then
If IsNull(DMax("[Confirmation_Num]", "Scheduled_Appts")) Then
Me.tbConfirmation.Value = 100000
Else
Me.tbConfirmation.Value = DMax("[Confirmation_Num]", "Scheduled_Appts") + 1
End If
End If
ElseIf Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Not Me.cobCarrier.Value = "" Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose either Shipping or Recieving for this Appointment!"
Cancel = True
ElseIf (Not Me.cbIncoming = 0 Or Not Me.cbOutgoing = 0) And Me.cobCarrier.Value = "" Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose a Carrier for this Appointment!"
Cancel = True
ElseIf Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Me.cobCarrier.Value = "" And Not IsNull(Me.tbSchTime.Value) Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose a carrier and either Shipping or Recieving for this Appointment!"
Cancel = True
ElseIf Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Me.cobCarrier.Value = "" And Not IsNull(Me.tbSchTime.Value) _
And IsNull(Me.tbConfirmation) And Me.tbDate = "" Then
Me.Undo
End If
blnDelete = False
'End
End Sub
Private Sub txtApptDate_Exit(Cancel As Integer)
On Error GoTo err_handler
DoCmd.Requery
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cbIncoming_Click()
On Error GoTo err_handler
blnDelete = False
testAddAppt
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cbOutgoing_Click()
On Error GoTo err_handler
blnDelete = False
testAddAppt
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cbViewRec_Click()
On Error GoTo err_handler
DoCmd.Requery
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cbViewShip_Click()
On Error GoTo err_handler
DoCmd.Requery
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cmdOpenDetails_Click()
Me.AllowEdits = True
If Not strGroupPolicy = "Users - View Only" Then DoCmd.RunCommand acCmdSaveRecord
dtLastViewed = Form_frmScheduled_Appts.cldrApptDates.Value
On Error GoTo exitProc
DoCmd.OpenForm "frmOpenDetails", , , "Appt_Id = " & Me.tbApptID
DoCmd.Close acForm, "frmScheduled_Appts"
exitProc:
Exit Sub
End Sub
Private Sub cobCarrier_Change()
On Error GoTo err_handler
testAddAppt
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub Form_Current()
' Call our redraw function.
' We have to do this here because of a bug using
' Withevents to sink a Form's events from a Class module.
CF.Redraw
End Sub
Private Sub Form_Error(DataErr As Integer, Response As Integer)
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = Error$
End Sub
Private Sub Form_Load()
' startup our class
Set CF = New clsConditionalFormatting
On Error GoTo err_handler
On Error Resume Next
DoCmd.Requery
On Error GoTo 0
' You must set a reference to a TextBox control
' that you have placed anywhere in the Detail section.
' Don't worry about the control's size or placement.
' The class will position, size and set it's properties as required.
CF.BGTextBox = Me.tbArrTime
'CF.BGTextBox = Me.Sch_Time
' Set the desired Highlight Color
CF.HighlightColor = CLng(vbRed) ' <<<<< this can be changed to the desired color
'CF.ShowHighlighting = True
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub tbArrTime_Click()
On Error GoTo err_handler
If IsNull(Me.tbArrTime) And Not Me.NewRecord Then
Me.tbArrTime.Value = Format(Now(), "hh:mm AM/PM")
Me.tbArrDate.Value = Date
End If
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub tbDepTime_Click()
On Error GoTo err_handler
If Me.AllowEdits = True And IsNull(Me.tbDepTime) And Not IsNull(Me.tbArrTime) And Not Me.NewRecord Then
Me.tbDepTime.Value = Format(Now(), "hh:mm AM/PM")
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm "frmCompleteAppts", , , "Appt_Id = " & Me.tbApptID
End If
Exit Sub
err_handler:
ErrorCode
End Sub
'------------------------------------------------------------
' cmdDelete_Click
'
'------------------------------------------------------------
Private Sub cmdDelete_Click()
On Error GoTo cmdDelete_Click_Err
blnDelete = True
strDelRecord = "Appts"
DoCmd.OpenForm "frmDelete"
Form_frmDelete.lblError.Caption = "Are you sure you want to delete Apptointment CW" & _
Form_frmScheduled_Appts.tbConfirmation & "?"
cmdDelete_Click_Exit:
Exit Sub
cmdDelete_Click_Err:
ErrorCode
End Sub
Private Sub Form_BeforeUpdate(Cancel As Integer)
On Error GoTo err_handler
If IsNull(Me.tbDate) Then
If Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Not Me.cobCarrier.Value = "" Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose either Shipping or Recieving for this Appointment!"
Cancel = True
ElseIf (Not Me.cbIncoming = 0 Or Not Me.cbOutgoing = 0) And Me.cobCarrier.Value = "" Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose a Carrier for this Appointment!"
Cancel = True
ElseIf Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Me.cobCarrier.Value = "" And Not IsNull(Me.tbSchTime.Value) Then
DoCmd.OpenForm "frmGeneralError"
Form_frmGeneralError.lblError.Caption = "You must chose a carrier and either Shipping or Recieving for this Appointment!"
Cancel = True
ElseIf Me.cbIncoming = 0 And Me.cbOutgoing = 0 And Me.cobCarrier.Value = "" And Not IsNull(Me.tbSchTime.Value) _
And IsNull(Me.tbConfirmation) And Me.tbDate = "" Then
Me.Undo
End If
End If
If IsNull(Me.tbArrTime.Value) Then Me.tbArrDate.Value = ""
If Not blnDelete Then
TestAppt Cancel
End If
blnDelete = False
Exit Sub
err_handler:
ErrorCode
End Sub
Private Sub cobCarrier_NotInList(NewData As String, Response As Integer)
On Error GoTo err_handler
If MsgBox("The Item Entered is not in database, would you like to add it?", vbYesNo) = vbYes Then
CurrentDb.Execute "INSERT INTO [Carrier Table](Carrier) " & _
"Values('" & NewData & "')", dbFailOnError
Response = acDataErrAdded
End If
Exit Sub
err_handler:
ErrorCode
End Sub