Results 1 to 6 of 6
  1. #1
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    188

    Hide Controls based on query

    Trying to morph code from a different function. I'm trying to hide some controls based on the results of query field [RetLocationID]. I don't get an error, but it doesn't work either. The controls are always hidden. What am I dong wrong?



    Code:
    Private Sub PageFooterSection_Format(Cancel As Integer, FormatCount As Integer)
    'THIS CODE FOR [GiftMsg] WORKS AS EXPECTED
    If [GiftMsg] = "00" Then
            Me!GiftMsgBox.Visible = False
        Else
            Me!GiftMsgBox.Visible = True
        End If
    
    'THIS CODE DOES NOT WORK    
        Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim varReturnID As String
        Dim varPackListQuery As String
        Dim varReportName As String
    
    
        varPackListQuery = "qry_PackingList"
        varReportName = "Packing List"
    
    
        Set db = CurrentDb()
    
    
        Set rs = db.OpenRecordset("SELECT Distinct [RetLocationID] FROM " & varPackListQuery, dbOpenSnapshot)
    
    
         varReturnID = rs("RetLocationID")
     
    If varReturnID = "SM" Or varReturnID = "SN" Or varReturnID = "SV" Then
            Me!BarCodeMsg.Visible = True
            Me!BarCode.Visible = True
            Me!BarCodeReceiptID.Visible = True
            Me!StoreAssociate.Visible = True
            Me!StoreAssocInst.Visible = True
        Else
            Me!BarCodeMsg.Visible = False
            Me!BarCode.Visible = False
            Me!BarCodeReceiptID.Visible = False
            Me!StoreAssociate.Visible = False
            Me!StoreAssocInst.Visible = False
        End If
        
        rs.Close
        Set rs = Nothing
        Set db = Nothing
    End Sub
    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,518
    Set a breakpoint or use this to see what varReturnID contains:

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

    You realize that will only use the first record returned by the query if there are more than one?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    188
    If I understand your SQL testing code correctly, I should be able to highlight the below, run, then see results in the lower window, correct? See attached. All I get is a window pop up looking for a macro name.

    Code:
    Dim db As DAO.Database
        Dim rs As DAO.Recordset
        Dim varReturnID As String
        Dim varPackListQuery As String
        Dim varReportName As String
    
    
        varPackListQuery = "qry_PackingList"
        varReportName = "Packing List"
    
    
        Set db = CurrentDb()
        strSql = "SELECT Distinct [RetLocationID] FROM " & varPackListQuery
        Set rs = db.OpenRecordset(strSql, dbOpenSnapshot)
        Debug.Print strSql
    thanks
    Attached Thumbnails Attached Thumbnails S1.jpg  

  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,518
    I don't think you can run it that way. I was thinking putting

    debug.print varReturnID

    after the line that sets it, run the code normally, and see what's returned. You could also set a breakpoint and hover over the variable. Stepping through the code might reveal something too. Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    shank is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Sep 2010
    Posts
    188
    I did get results but found I needed to further define the query. I took the fast route and added a hidden control on the report and referenced that. It worked.

    Thanks
    Last edited by shank; 06-05-2019 at 03:29 PM.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Glad you got it working.
    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. Hide controls based on value list.
    By MrOhhmy in forum Forms
    Replies: 4
    Last Post: 10-16-2018, 12:07 AM
  2. How to hide controls (Tab control)
    By Bill Neilsen in forum Forms
    Replies: 3
    Last Post: 08-07-2014, 02:27 AM
  3. Replies: 1
    Last Post: 06-08-2012, 11:14 AM
  4. Replies: 4
    Last Post: 04-18-2012, 10:42 PM
  5. Combobox-dependent show/hide controls
    By focosi in forum Forms
    Replies: 3
    Last Post: 07-31-2011, 06: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