Results 1 to 4 of 4
  1. #1
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60

    two combo box to open report

    Hi,

    This should be an easy one but I'm having a hard time understanding when to use double/single quotes, ampersands and brackets in VBA.

    Anyways I have two combo boxes, one that chooses a Site (bound to SiteID) and the other chooses a Location (bound to LocationID) based on the Site. That works great. I have a query that has both SiteID and LocationID in it and it works just fine when I run a report based off of SiteID but when I try to combine the two things don't work.



    Code:
    Dim strWhere As StringIf Not IsNull(Me.cboSiteName) Then
    
        strWhere = "[SiteID] = '" & Me.cboSiteName & "'"
    End If
        
    Select Case Me.cboReports.Value
    Case "Basic Report"
        If Me.cboSiteName = 0 Then
            DoCmd.OpenReport Reportname:="rptCalibrationALL", _
            View:=acViewReport
        Else
            DoCmd.OpenReport "rptCalibrationALL", acViewReport, , strWhere, acWindowNormal
        End If

    Anyways while I was typing this I figured it out, LocationID is a number, SiteID is 3 text characters so I was trying to use single quotes when I only needed double. All works now after I added another one of these:
    Code:
    If Not IsNull(Me.cboLocationName) Then    strWhere = " SiteID = '" & cboSiteName & "' And LocationID = " & cboLocationName & ""
    End If

    So I really don't have any question except... what would you do differently to make it better and does anyone have a good resource to explain how to quote literal strings in SQL/VBA and where ampersands fit in?! Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    There's a decent tutorial here:

    http://www.baldyweb.com/BuildSQL.htm

    What you're doing would follow the same rules.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    benjammin is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Nov 2010
    Posts
    60
    Thanks for the link!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Open Report From List Using Combo Box
    By burrina in forum Forms
    Replies: 5
    Last Post: 11-20-2012, 10:20 AM
  2. Open report in accordance with combo
    By fabiobarreto10 in forum Reports
    Replies: 2
    Last Post: 05-24-2012, 09:21 AM
  3. Open Report by Combo box
    By rck3 in forum Reports
    Replies: 2
    Last Post: 05-07-2012, 05:29 PM
  4. Replies: 1
    Last Post: 09-21-2011, 03:21 AM
  5. Using a combo box to open a report
    By Bill Casanova in forum Forms
    Replies: 24
    Last Post: 05-24-2011, 10:42 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