I have a form that is opened through the "After Update" Event of a combo box. The combo box presents an integer to a DoCmd.OpenForm method so that the form opens showing information for a desired record. The following code snippet shows how the form is opened:
Function SearchByNameLO_Up_Top()
Dim BorrowerQuickSearchBtn As String
Dim BorrowerQuickSearchBtn1 As String
On Error GoTo SearchByNameLO_Up_Top_Err
' Name the Borrower Quick Search Button
BorrowerQuickSearchBtn = "Forms!" & strSwitchboard & "!Combo114"
BorrowerQuickSearchBtn1 = "[Forms]![" & strSwitchboard & "]![combo114]"
DoCmd.SetWarnings False
If (IsNull(BorrowerQuickSearchBtn) = True) Then
End
End If
If (IsNull(DLookup("InUseBy", "qryInUseStatusCP")) = True Or DLookup("clientid", "qryInUseStatus") <> BorrowerQuickSearchBtn) Then
DoCmd.OpenForm "LO View", acNormal, "", "[client id]=" & BorrowerQuickSearchBtn1, , acNormal
End If
If (DLookup("clientid", "qryInUseStatus") = BorrowerQuickSearchBtn) Then
fncFileInUseMsgbox
End If
If (DLookup("clientid", "qryInUseStatus") = BorrowerQuickSearchBtn) Then
DoCmd.OpenForm "LO View", acNormal, "", "[client id]=" & BorrowerQuickSearchBtn1, acReadOnly, acNormal
End If
In this example, Combo114 is the combo box
This code works perfectly.
However when I make a copy of that combo box and rename it and create another bit of code:
Function PullUpAnotherClientInLOView()
Dim SelectedUser As Integer
On Error GoTo PullUpAnotherClientInLOView_Err
DoCmd.SetWarnings False
SelectedUser = Forms![Lo View]!cboLoViewClientQuickSearch
' If there is nothing to search for then exit
If (IsNull(SelectedUser) = True) Then
End
End If
DoCmd.Close acForm, "LO View"
' If no one else is looking at this client other than the current user then open "LO View" for this client
If (IsNull(DLookup("InUseBy", "qryInUseStatusCP")) = True Or DLookup("clientid", "qryInUseStatus") <> SelectedUser) Then
DoCmd.OpenForm "LO View", acNormal, "", "[Client ID] = SelectedUser", , acNormal
End If
When the DoCmd.OpenForm method is run in this instance, I am prompted for the value of "SelectedUser", even though it is obviously assigned in the code. Once I enter it, the rest of the code runs fine. When I "Add Watch", the variable "SelectedUser" displays its assigned value just fine.