Hi,
Last month I posted a query on this forum. It solved my problem to the extent that the form being used was a bound form. I am now trying to make it work with an unbound form in my specific scenario. The relevant code is posted here as well.
The way it should work is to keep the current Dispatch ID same as long as selection in 'ToLoc' combo box is the same. But a new Dispatch ID to be generated as soon as a new selection is made in the 'ToLoc' combo box. However, I am getting error at "cboToLoc". How should this problem be rectified? Regards
Last month I posted a query on this forum. It solved my problem to the extent that the form being used was a bound form. I am now trying to make it work with an unbound form in my specific scenario. The relevant code is posted here as well.
Code:
Private Sub cboToLoc_AfterUpdate()
Dim lngDispID As Long
Dim lngNewDispID As Variant
If Me.cboToLoc.ListIndex <> -1 Then
lngDispID = Nz(DMax("DispatchID", "tblDispatches"), 0) + 1
lngNewDispID = Nz(DMax("DispatchID", _
"tblDispatches", _
"cboToLoc = " & Me.cboToLoc & " And WorkDate = #" & Format$(Me!WrkDate, "mm/dd/yyyy") & "#"), lngDispID)
Me![DN_ID] = lngNewDispID
Else
Me![cboToLoc] = Null
Me![DN_ID] = Null
End If
End Sub
The way it should work is to keep the current Dispatch ID same as long as selection in 'ToLoc' combo box is the same. But a new Dispatch ID to be generated as soon as a new selection is made in the 'ToLoc' combo box. However, I am getting error at "cboToLoc". How should this problem be rectified? Regards