Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    MikeN is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    39
    June7,

    This is what I have so far. Hopefully I'm on the right track. The loop is recognizing the listbox selections as TripID and prints the appropriate TripID number. Debugging the initial strWhere prints "TripID", then I trim the "," to get "TripID" (with the words TripID being the actual TripID value). If I choose multiple listbox options then I get "TripID","TripID".



    I added the Where to my original strSQL code to try to pass the resulting strWhere results into the SQL. I'm not quite sure if my strWhere is the appropriate format, or if its getting passed in the SQL correctly. I've been getting 'data type mismatch in criteria expression' error on the DoCmd.OpenQuery line when I run it though. I'd be thankful if you have the time to take another look at it and see if I'm headed in the right direction. I re-attached my updated db in case you need to look at anything.

    Code:
    Private Sub qryBeltSurvey_Click()
        Dim db As DAO.Database
        Dim qdf As DAO.QueryDef
        
        Dim varItem As Variant
        Dim strCriteria As String
        Dim strWhere As String
        Dim strDescrip As String
        Dim lngLen As Long
        Dim strDelim As String
        Dim strDoc As String
        Dim strSQL As String
        
        Set db = CurrentDb()
        Set qdf = db.QueryDefs("BeltQuerybyInstructor")
        Set frm = Forms!frm_QueryBuilder
        Set ctl = frm!listDates
    
    
        strDelim = """"
    
    'Loop through the ItemsSelected in the list box.
        With ctl
            For Each varItem In .ItemsSelected
                If Not IsNull(varItem) Then
                    strWhere = strWhere & strDelim & .ItemData(varItem) & strDelim & "," 
                End If
             Next
        End With
        Debug.Print strWhere   ' --> prints "value",
        
        'trim trailing comma
            strWhere = Left(strWhere, Len(strWhere) - 1)
                    Debug.Print strWhere  ' --> prints "value"
            
                strSQL = "TRANSFORM Count(tbl_BeltSurveyData.TotalCount) AS CountOfTotalCount " & vbCrLf & _
                    "SELECT tbl_trip.TripDate, tbl_trip.Instructor, tbl_trip.SampleMethod, tbl_trip.SampleSite, tbl_BeltSurvey.Observers, tbl_BeltSurvey.TransectNum, tbl_BeltSurvey.SurveyNotes " & vbCrLf & _
                    "FROM tbl_trip INNER JOIN (tbl_BeltSurvey INNER JOIN (tbl_beltSurveySpecies INNER JOIN tbl_BeltSurveyData ON tbl_beltSurveySpecies.BeltSurveySpeciesID = tbl_BeltSurveyData.BeltSurveySpecies) ON tbl_BeltSurvey.BeltSurveyID = tbl_BeltSurveyData.BeltSurveyID) ON tbl_trip.TripID = tbl_BeltSurvey.TripID " & vbCrLf & _
                    "WHERE tbl_trip.TripID IN (" & strWhere & ") " & vbCrLf & _
                    "GROUP BY tbl_trip.TripID, tbl_trip.TripDate, tbl_trip.Instructor, tbl_trip.SampleMethod, tbl_trip.SampleSite, tbl_trip.TripNotes, tbl_BeltSurvey.Observers, tbl_BeltSurvey.TransectNum, tbl_BeltSurvey.SurveyNotes " & vbCrLf & _
                    "PIVOT tbl_beltSurveySpecies.Taxa;"
            
        qdf.SQL = strSQL
        DoCmd.OpenQuery "BeltQuerybyInstructor"
       
    End Sub

  2. #17
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    TripID is a number type field, do not want the parameter values enclosed with quote marks. Remove the strDelim concatenation. These delimiters are for text type field parameters.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #18
    MikeN is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Jan 2015
    Posts
    39
    Quote Originally Posted by June7 View Post
    TripID is a number type field, do not want the parameter values enclosed with quote marks. Remove the strDelim concatenation. These delimiters are for text type field parameters.
    That fixed it! It's working! Thank you!!

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Weird Crosstab results
    By SteveApa in forum Queries
    Replies: 2
    Last Post: 01-28-2015, 07:04 AM
  2. Query to sum results of two crosstab queries
    By Gryphoune in forum Queries
    Replies: 3
    Last Post: 08-05-2014, 12:15 PM
  3. Replies: 4
    Last Post: 09-12-2013, 03:58 PM
  4. Sorting Crosstab query results?
    By Dragongem in forum Queries
    Replies: 1
    Last Post: 06-13-2013, 09:21 PM
  5. Replies: 16
    Last Post: 09-23-2009, 08:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums