I'm putting together a application (if you can call it that) that is an Access frontend that accesses a SQL 2000 database. So far I'm using ADO to code all the forms. It seemed as though I had a combo box that would be populated by a stored procedure and this combo box existed on several forms so I wanted to save some repetitive code and just create a global sub in a module that would do this and just call that sub on the forms open event. I ran into problems. No matter what I do, the code craps out when it hits the name of the combo box. When I step through the code and mouse over the combo box name it says cboEmployee=Null
Here is what I have in the module:
CODE
Public Sub FillEmpCboBox(frm As Form, cbo As ComboBox)
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
cnn.Open EngCnn
Set cmd.ActiveConnection = cnn
cmd.CommandText = "proc_Get_Employees"
cmd.CommandType = adCmdStoredProc
Set rs = cmd.Execute()
rs.MoveFirst
While Not rs.EOF
frm.cbo.AddItem rs!EmpID & ";" & rs!EmpName
rs.MoveNext
Wend
Set cmd = Nothing
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Sub
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Set cnn = New ADODB.Connection
Set cmd = New ADODB.Command
cnn.Open EngCnn
Set cmd.ActiveConnection = cnn
cmd.CommandText = "proc_Get_Employees"
cmd.CommandType = adCmdStoredProc
Set rs = cmd.Execute()
rs.MoveFirst
While Not rs.EOF
frm.cbo.AddItem rs!EmpID & ";" & rs!EmpName
rs.MoveNext
Wend
Set cmd = Nothing
rs.Close
Set rs = Nothing
cnn.Close
Set cnn = Nothing
End Sub
I'm calling this sub in the forms open event with this:
CODE
Call FillEmpCboBox(Form_frmReqForm_Engineering, cboEmployee)
frmReqForm_Engineering being the name of the form that has the combo box in it and cboEmployee being the name of the control.
Again, it's my limited knowledge that is really the culprit here.
Thanks so much for any help.