I'm new to VBA and this may be very basic so bear with me. I'm trying to develop a process where I have multiple list boxes. I want to populate the first list box and be able to select records from the first list box and move the selected records to a second list box for additional processing.
I'm having problem with populating the first list box. I can get this working using a straight selection from a sql server table but the minute I change it to use columns using a query I've created it fails with Run time error -2147217904 (No value given for one or more req parameters)
My query does use fields filled in from the form but by the time I execute my list box, all those fields should be available. Is this something that can't be done? Or does anyone else have any other suggestions on how to accomplish this when you need to compare values from the Form to narrow down your criteria. In order for this process to work my Row Source Type has to be set as a VALUE LIST.
Private Sub Employeelist_Enter()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String, strItem As String
strSQL = "SELECT EmployeeDept_qry.zLName, EmployeeDept_qry.zFName, EmployeeDept_qry.BadgeID FROM EmployeeDept_qry Where EmployeeDept_qry.zDeptdesc = [Forms]![Main_Frm]![DepartmentList];"
Set cn = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
Do Until rs.EOF
strItem = rs.Fields("zLname").Value & ";" & rs.Fields ("zfName").Value & ";" & rs.Fields("zBadgeId").Value
Me.Employeelist.AddItem strItem
'Row Source Type must be Value List
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set cn = Nothing
End Sub
I'm having problem with populating the first list box. I can get this working using a straight selection from a sql server table but the minute I change it to use columns using a query I've created it fails with Run time error -2147217904 (No value given for one or more req parameters)
My query does use fields filled in from the form but by the time I execute my list box, all those fields should be available. Is this something that can't be done? Or does anyone else have any other suggestions on how to accomplish this when you need to compare values from the Form to narrow down your criteria. In order for this process to work my Row Source Type has to be set as a VALUE LIST.
Private Sub Employeelist_Enter()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String, strItem As String
strSQL = "SELECT EmployeeDept_qry.zLName, EmployeeDept_qry.zFName, EmployeeDept_qry.BadgeID FROM EmployeeDept_qry Where EmployeeDept_qry.zDeptdesc = [Forms]![Main_Frm]![DepartmentList];"
Set cn = Application.CurrentProject.Connection
Set rs = New ADODB.Recordset
rs.Open strSQL, cn, adOpenForwardOnly, adLockOptimistic
Do Until rs.EOF
strItem = rs.Fields("zLname").Value & ";" & rs.Fields ("zfName").Value & ";" & rs.Fields("zBadgeId").Value
Me.Employeelist.AddItem strItem
'Row Source Type must be Value List
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set cn = Nothing
End Sub