Code:
Private Sub cmdBookDelivery_Click()
Dim iNoDate As Integer
Dim iNumFurn As Integer
Dim strTimeNeeded As String
Dim strFullName As String
Dim strAddress As String
Dim LAncillaries As Integer
On Error GoTo ErrHandler
If IsNull(Me.Invoice) = True Then
MsgBox "Please select who to invoice."
Me.Invoice.SetFocus
Exit Sub
Else
If IsNull(Me.TakenBy) = True Then
MsgBox "Please fill in 'Taken By' field."
Me.TakenBy.SetFocus
Exit Sub
Else
If IsNull(Me.DeliveryDate) = True Then
iNoDate = MsgBox("There is no delivery date set for this delivery. Book anyway?", vbOKCancel)
If iNoDate = vbOK Then
'Do nothing
Else
Exit Sub
End If
Else
'Do nothing
End If
DoCmd.RunCommand acCmdSaveRecord
If DCount("*", "qryNewPendingDelFurnSub", "[Free] < [NumberAllocated] AND [NumberAllocated]>0 AND DeliveryID = " & Forms!frmDelivery.DeliveryID) > 0 Then
DoCmd.OpenForm "frmOverAllocationWarningBox"
Else
If DateDiff("d", [DateTaken], [DeliveryDate]) > 5 Then
MsgBox "Have you sent a postcard?", , "Reminder"
Else
'Do nothing
End If
If Me.Invoice.Value = "Agency" Then
MsgBox "Have you requested a purchase order number?", , "Reminder"
Else
'Do nothing
End If
iNumFurn = DLookup("TotalNumRequested", "qryTotalNumRequestedAllocatedFurniture", "DeliveryID = " & Me.DeliveryID)
If iNumFurn < 4 Then
strTimeNeeded = "1/2 hour"
ElseIf iNumFurn < 11 Then
strTimeNeeded = "1 hour"
ElseIf iNumFurn < 16 Then
strTimeNeeded = "1 & 1/2 hour"
Else
strTimeNeeded = "2 hour"
End If
strFullName = DLookup("ContactFirstName", "tblClientDonorContact", "ContactID = " & Me.ContactID) & " " & _
DLookup("ContactLastName", "tblClientDonorContact", "ContactID = " & Me.ContactID)
strAddress = DLookup("Area", "tblAddresses", "AddressID = " & Me.AddressID) & ", " & _
DLookup("Postcode", "tblAddresses", "AddressID = " & Me.AddressID)
'**************************** HERE *************************************
InputBox "Please add an appointment in the calendar." & vbCrLf & vbCrLf & "Appointment length:" & vbCrLf & strTimeNeeded & _
vbCrLf & vbCrLf & "Copy and paste the following:", "Reminder", "Delivery - " & strFullName & " - " _
& strAddress & " - " & Me.DelBeforeAfter
'**********************************************************************
DoCmd.SetWarnings False
DoCmd.OpenQuery "qryDeliveryUpdateStock"
DoCmd.SetWarnings True
If DCount("*", "tblAllocatedAncillaries", "DeliveryID = " & Forms!frmDelivery.DeliveryID) > 0 Then
LAncillaries = MsgBox("View/edit ancillary report before printing?", vbYesNoCancel)
If LAncillaries = vbYes Then
DoCmd.OpenReport "rptAncillaryReport", acViewReport, , "DeliveryID = " & Forms!frmDelivery.DeliveryID
DoCmd.Close acForm, "frmDelivery"
MsgBox "Delivery booked."
ElseIf LAncillaries = vbNo Then
DoCmd.OpenReport "rptAncillaryReport", acViewReport, , "DeliveryID = " & Forms!frmDelivery.DeliveryID
Application.DoCmd.SelectObject acReport, "rptAncillaryReport"
DoCmd.PrintOut acPages, 2, 2
DoCmd.Close acReport, "rptAncillaryReport"
DoCmd.Close acForm, "frmDelivery"
MsgBox "Delivery booked."
DoCmd.OpenForm "frmPhoneCalls", acNormal, , , acFormAdd
ElseIf LAncillaries = vbCancel Then
MsgBox "Delivery booked. Ancillary sheet can be printed from Pending Deliveries."
DoCmd.Close acForm, "frmDelivery"
DoCmd.OpenForm "frmPhoneCalls", acNormal, , , acFormAdd
End If
Else
DoCmd.Close acForm, "frmDelivery"
MsgBox "Delivery booked."
DoCmd.OpenForm "frmPhoneCalls", acNormal, , , acFormAdd
End If
End If
End If
End If
ErrExit:
Exit Sub
ErrHandler:
MsgBox Err.Description, vbOKOnly, "ERROR"
LogError "cmdBookDelivery_Click", Err.Number, Err.Description
Resume ErrExit
End Sub