I've run into a snag trying to load values from a table into a combo box so the user can select from it. My first try attempted to do this at Form_Open, which consistently threw a 2474 error at
Code:
Screen.ActiveControl.RowSource = Screen.ActiveControl.RowSource & """ & Employee_line & "";"
Further reading led me to believe that the control was not available for accessing at Form_Open, so my next try was a BeforeUpdate event for the combo box itself. I receive no error, but I get no values loaded into the combo box when I click on it (I've checked to ensure I have entries in the Employee table). Code is below, this is my first foray into MSACCESS and if someone has any insight I'd greatly appreciate it.
Code:
Private Sub Employee_List_BeforeUpdate(Cancel As Integer)
Dim CAT_record As ADODB.Recordset 'Declares a recordset handle to hold data from Employee table
Set CAT_record = New ADODB.Recordset 'Initializes CAT_record recordset
CAT_record.ActiveConnection = CurrentProject.Connection 'Binds the recordset handle to the existing connection
CAT_record.CursorType = adOpenStatic 'Only pull records as they are now (not dynamic)
CAT_record.Open "Select * from Employee ORDER BY 'Lname'" 'Pull records from Employee Table, sort by last name
DoCmd.GoToControl "Employee_List" 'Set focus to combo box for names
Do Until CAT_record.EOF 'Loop through all Employee table record
Employee_line = CAT_record("Lname") & ", " & CAT_record("Fname") & " " & CAT_record("Grade") 'Create new entry to choose from
Screen.ActiveControl.RowSource = Screen.ActiveControl.RowSource & """ & Employee_line & "";" 'Append to list in combo box
CAT_record.MoveNext 'Access next record
Loop 'Repeat until End Of File (EOF)
CAT_record.Close 'Close the recordset
Set CAT_record = Nothing 'Unbind the handle
End Sub