I have a need to be able to clear specific combo boxes when certain actions are taken. To do this efficiently, I need to be able to use string variables (or similar) to identify the correct combo to be cleared. Several searches across the web have yielded no insight into a solution.
Below is my first attempt, which obviously doesn't work. When it hits the SET line, I get "...can't find the field 'strCombo' referred to...". Obviously, it's looking for an object, rather than a string. How can I use a string to identify which object I need? It seems external-facing functions, like GetObject, are designed to work this way. Is there a similar function that I can use for Access objects?
Public Function ClearCombo(frm As Form)
On Error GoTo Err_Handler
Dim strCommand As String ' used for retrieving the name of the current control
Dim strSelect As String ' used to store the ID number of the current button
Dim lngPosition As Long ' used to store the position of the underscore character
Dim strCombo As String ' used to build the name of the combo box
Dim cbo As ComboBox
strCommand = Screen.ActiveControl.Name
lngPosition = InStr(1, "_", strCommand, vbTextCompare)
strSelect = Right(strCommand, Len(strCommand) - (lngPosition + 1))
strCombo = "cboLead_" & strSelect
Set cbo = frm!strCombo
cbo.Value = Null
Exit_Handler:
Exit Function
Err_Handler:
Call LogError(Err.Number, Err.Description, "ClearCombo")
Resume Exit_Handler
End Function