GregoireLeGros
Registered User.
- Local time
- Today, 20:40
- Joined
- Oct 31, 2007
- Messages
- 13
On my form I have a combo box where the user can select the sex of a person. I had set the row source of the combo to a table, tblSex and this works fine. Now I want to programatically add the table entries ( simply male or female) to the row source, having set the combobox to value list.
I cant see how to pass the combobox and tablename parameters and I am getting an error on form load "The expression you entered as the event property setting produced the following error: UserDefined type not defined"
The calling procedure from frmPeople is
The called procedure PopulateCombo() is
I think the way the parameters combobox and tablename are passed is incorrect. I want to write a robust procedure which I can use for each of the comboboxes on my form.
I cant see how to pass the combobox and tablename parameters and I am getting an error on form load "The expression you entered as the event property setting produced the following error: UserDefined type not defined"
The calling procedure from frmPeople is
Code:
'---------------------------------------------------------------------------------------
' Procedure : Form_Load
' Author : Administrator
' Date : 21/11/2013
' Purpose :
'---------------------------------------------------------------------------------------
'
Private Sub Form_Load()
On Error GoTo Form_Load_Error
Call PopulateCombo(cmbSex, "tblSex")
On Error GoTo 0
Exit Sub
Form_Load_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Form_Load of VBA Document Form_frmPeople"
End Sub
The called procedure PopulateCombo() is
Code:
Public Sub PopulateCombo(ByVal sCtl As ComboBox, ByVal sTable As acTable)
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset(sTable)
With sCtl
rst.MoveFirst
Do While Not rst.EOF
.AddItem Item:=rst(0) 'the table has only one column
rst.MoveNext
Loop
End With
rst.Close
Set db = Nothing
End Sub
I think the way the parameters combobox and tablename are passed is incorrect. I want to write a robust procedure which I can use for each of the comboboxes on my form.