I have a form in access that contains a recordset that is to be populated based on the selection of a dropdown list. I have tested the query and it definitely works if I set the variable data directly. However, I cannot seem to get it to work. I attempted to set the value of a hidden text box in order to see if I could access the data that way, however, I continue to get the Run-time error: 2185 ‘You can’t reference a property or method for a control unless the control has focus.
This is the code in the subroutine:
Private Sub pickdate_AfterUpdate()
Me![pickdate].SetFocus
Me![tb_HiddenDate] = Me![pickdate].Text
Forms!mainForm!subForm.Requery
End Sub
As an aside, if I do Debug.Print(Me![pickdate]) it simply returns the index of the selected item. Same thing for Me![pickdate].Value. Me![pickdate].Text throws the exception, even in the AfterUpdate handler for pickdate.
I have looked into this thread: MS Access: An error in vba of my form, but it does not work in this case. I am at my wit’s end right now trying to figure out why this isn’t working as expected. Anyone have any other suggestions?
Temporarily change the After Update procedure to see what you’re dealing with. Perhaps
pickdateincludes 2 columns: the first a number; and the second the text you want to retrieve.View the output in the Immediate window (Ctrl+g).