I really don't like debugging even though I know it's necessary.
I'm getting a run-time error 2465, application-defined or object-defined error, that I don't know how to fix, despite multiple searches in various Access forums. The line highlighted below is where I'm getting the error. I'm sure there are ways to optimize my code but I'm just trying to get this done at the moment.
I'm getting a run-time error 2465, application-defined or object-defined error, that I don't know how to fix, despite multiple searches in various Access forums. The line highlighted below is where I'm getting the error. I'm sure there are ways to optimize my code but I'm just trying to get this done at the moment.
Code:
Public Function SetDueDate()
Dim deliveryDue As Date 'calculated delivery date
Dim startDate As Date 'DO/TO start date
Dim Msg, Style, Title, Response
DoCmd.OpenForm "frmDeliveriesReceived"
'check if event date is blank
If IsNull(Forms!frmDeliveriesReceived.Form.Event1_Date) Then 'if event date is blank
'check if event is DAC
If Forms!frmDeliveriesReceived.Form.Event1_Due_For.Column(1) = "After Contract Award" Then 'if it is DAC
'get start date
[highlight]startDate = DLookup("Start_Date", "tblDeliveryTaskOrders", "Task_ID = " & Forms!frmDeliveriesReceived.frmDeliveriesReceived_Subform.Form.Delivery_Task_Order)[/highlight]
SetDueDate = FindDueDate(Forms!frmDeliveriesReceived.Form.Event1_Due_For.Column(1), startDate) 'call function to determine calculated due date
Else 'if event date is blank and not DAC, display error message
'set up msgbox
Msg = "Event Date cannot be blank."
Style = vbOKOnly
Title = "Check Blank Event Date"
'display msgbox
Response = MsgBox(Msg, Style, Title)
SetDueDate = "" 'set due date to blank
'Exit Function 'return to calling sub
End If
Else 'if event date is not blank
'check if manual date selected
If Forms!frmDeliveriesReceived.Form.Manual_Date_Due = True Then 'if it is selected
'verify that it is correct
SetDueDate = FindDueDate(Forms!frmDeliveriesReceived.Form.Event1_Due_For.Column(2), Forms!frmDeliveriesReceived.Form.Event1_Date) 'call function to determine calculated due date
'check that current date equals calculated date
If Forms!frmDeliveriesReceived.Form.Event1_Date = SetDueDate Then 'if it matches
SetDueDate = "" 'set due date to blank so calling sub will ignore it
Exit Function 'return to calling sub
Else 'if date does not match, show error message
'set up msgbox
Msg = "Initial Due Date is set to " & Forms!frmDeliveriesReceived.Form.Event1_Date & vbCrLf & _
"should be " & deliveryDue & "." & vbCrLf & vbCrLf & _
"To keep the current date, press 'Yes.'" & vbCrLf & _
"To change the date, press 'No.'"
Style = vbYesNo
Title = "Verify Manual Date Set"
'display msgbox
Response = MsgBox(Msg, Style, Title)
If Response = vbNo Then 'if user selects No
'do nothing and keep SetDueDate at current calculated value
Exit Function ' return to calling sub
Else 'if user selects Yes
SetDueDate = "" 'set due date to blank so calling sub will ignore it
Exit Function 'return to calling sub
End If
End If
Else 'if manual date is not selected
'do nothing and keep SetDueDate at current calculated value
Exit Function 'return to calling sub
End If
End If
End Function