EDIT: Ignore any typos in the code field names - I changed them to preserve confidentiality (lame yes, but I have to). The logic of the code is the problem. Thanks!
Here is what my project is:
1) I query a database for a list of employees depending on criteria that the user inputs.
2) The recordset is then displayed in a list box.
3) The user can then select the desired employees from the list box (lets say they choose 30 out of 60 that are returned by the SQL statement).
4) After the user has selected the 30 employees he/she then clicks a command button to return their employee ID's into an array/dictionary to be used later to perform an action in a compeltely different sub/function.
THIS IS WHERE IT FAILS. I can access the dictionary from within this sub, but after I loop through the recordset and dump it into a dictionary object it dies when the sub dies. I MUST be able to access it at a later point when the user clicks another button (this other button interacts with a third party program and passes the employee IDs to it). I really can't wrap my head around how to do this... I was thinking I may need to create a class? even then that may be another monster to take on... any help is much appreciated..
Any thoughts?
Here is what I have so far:
Here is what my project is:
1) I query a database for a list of employees depending on criteria that the user inputs.
2) The recordset is then displayed in a list box.
3) The user can then select the desired employees from the list box (lets say they choose 30 out of 60 that are returned by the SQL statement).
4) After the user has selected the 30 employees he/she then clicks a command button to return their employee ID's into an array/dictionary to be used later to perform an action in a compeltely different sub/function.
THIS IS WHERE IT FAILS. I can access the dictionary from within this sub, but after I loop through the recordset and dump it into a dictionary object it dies when the sub dies. I MUST be able to access it at a later point when the user clicks another button (this other button interacts with a third party program and passes the employee IDs to it). I really can't wrap my head around how to do this... I was thinking I may need to create a class? even then that may be another monster to take on... any help is much appreciated..
Any thoughts?
Here is what I have so far:
Code:
Set dctEmployeeID = New Dictionary
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.Open "SELECT EmployeeLastName,EmployeeFirstName, ManagerName,EmployeeID FROM tblEmployeeInfo " & _
"WHERE EmployeeID <> '' AND Status='current'
ORDER BY EmployeeLastName", conn, adOpenForwardOnly, adLockReadOnly
Do While Not rs.EOF
Form.lstEmployees.AddItem rs!EmployeeLastName.Value & rs!EmployeeFirstName.Value & " (" & rs!ManagerName.Value & ")"
strEmployee = rs!AgentLastName.Value & rs!AgentFirstName.Value & rs!TMName.Value & rs!Location
strEmployee = Replace(strEmployee, " ", "")
'this part puts the concatenation of lastname, firstname, managername, and associates it with their employee ID which will be used later on in another function/sub
dctEmployeeID.Add UCase(strEmployee), rs!EmployeeID.Value
rs.MoveNext
Loop
rs.Close
conn.Close
Set conn = Nothing
Set rs = Nothing