Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MultiSelect Listbox doesnt update at the right time

Status
Not open for further replies.

Tash

MIS
Nov 3, 2001
62
0
0
US
Hi -
I have multiple "Multi-Select" listboxes setup on an Access form. I am trying to get one listbox (SelectGLDept) to populate the next listbox (SelectHRDept), which has a query behind it (QryMenuHRDept)to populate the second list box. For example, the user chooses the GL Departments from the first list, which will show all the related HR Departments to choose from in the second listbox.

The problem I am having is that the selection only appears in the second listbox AFTER I have clicked on another item in the first listbox. I need it to populate the items in the second listbox as soon as I have clicked on the item in the first listbox. It will only show items that I 'previously' clicked. Can someone help me with this?

Here is what I have so far in the On-Click event in the first listbox.

Private Sub SelectGLDept_Click()
Dim DB As DAO.Database
Dim qdf As DAO.QueryDef
Dim varItem As Variant
Dim strCriteria As String
Dim strSQL As String

Set DB = CurrentDb()
Set qdf = DB.QueryDefs("QryMenuHRDept")

For Each varItem In Me!SelectGLDept.ItemsSelected
strCriteria = strCriteria & ",'" & Me!SelectGLDept.ItemData(varItem) & "' "
Next varItem

If Len(strCriteria) = 0 Then
MsgBox "You did not select anything from the list" _
, vbExclamation, "Nothing to find!"
Exit Sub
End If

strCriteria = Right(strCriteria, Len(strCriteria) - 1)
strSQL = "SELECT tblMainSub.HRDeptNo, tblMainSub.HRDeptName FROM tblMainSub " & _
"WHERE tblMainSub.GLDeptNo IN(" & strCriteria & ")GROUP BY tblMainSub.HRDeptNo, tblMainSub.HRDeptName;"

DoCmd.Requery "SelectGLDept"
DoCmd.Requery "SelectHRDept"
DoCmd.Save acForm, "FormSelectAll"

qdf.sql = strSQL
Set DB = Nothing
 
That's ok - I figured it out, I had the qdf.sql = strSQL below my Save function. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top