• SQL statement & parameter (Acc 97 sr2 on 95b)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » SQL statement & parameter (Acc 97 sr2 on 95b)

    Author
    Topic
    #374062

    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! dizzy)

    Viewing 0 reply threads
    Author
    Replies
    • #603778

      Change the command:

      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;”

      to

      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;”

      HTH
      pat cheers

      NB. I would have answered sooner but I have just been down to Centrelink trying to find a job.

      • #603780

        Pat,

        I actually solved it another way by:

        (((tblJobAllocate.Employee) = [Forms]![frmEmpHours]![lstEmptots]))

        just before your post came in. This way, I do not need to define empname at all, but thanks for the info, once again, getting the syntax exactly right is a real pain.

    Viewing 0 reply threads
    Reply To: SQL statement & parameter (Acc 97 sr2 on 95b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: