I have a list box that shows a list of names and the total hours work given to each person. I am trying to write a function so that when a name is clicked in the list, a query will appear showing the jobs that the hours come from.
Private Sub lstEmptots_Click()
Dim varItm
Dim empname
varItm = lstEmptots.ListIndex
empname = lstEmptots.ItemData(varItm)
Dim chosen, strSQL
Dim db As DAO.Database
Set db = CurrentDb
Dim qry As QueryDef
Set qry = db.QueryDefs(“qryJobbyEmp”)
strSQL = “SELECT tblJobAllocate.[Job #], Sum(tblJobAllocate.Hours) AS SumOfHours, tblJobAllocate.Employee From tblJobAllocate GROUP BY tblJobAllocate.[Job #], tblJobAllocate.Employee HAVING ((tblJobAllocate.Employee) = empname) WITH OWNERACCESS OPTION;”
qry.SQL = strSQL
DoCmd.OpenQuery “qryJobbyEmp”, acViewNormal
End Sub
but when I run it, it pops up a parameter window asking for empname.
once again, what don’t I know? (be specific, I realize the list could be endless! )