Results 1 to 4 of 4
  1. #1
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97

    caling the recordset of a subform in VBA

    Hi all,
    I have frmX (bound to tblX, primary key [ID]) and sfmY (bound to tblY, primary key [IDbis]).
    I would like to apply conditional visibility to some controls on sfmY according to recordset position (basically, no visibility on first record and visibility on all other records).


    I'm using this code but this doesn't seem to work.

    Code:
    Dim rst As DAO.Recordset
    Set rst = Me!sfmY!RecordsetClone
    rst.MoveFirst
    Select Case Me!sfmY![IDbis]
    Case rst![IDbis]
            Me.[ctrl1].Visible = False
            Me.[ctrl2].Visible = False
    Case Else
            Me.[ctrl1].Visible = True
            Me.[ctrl2].Visible = True
    End Select
    rst.Close
        Set rst = Nothing
    What's wrong ???

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The syntax for referring to the controls on the subform is wrong. It is tricky when referring to subform objects. Maybe this will help:

    http://access.mvps.org/access/forms/frm0031.htm

  3. #3
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    thanks for the reference. I have modified my syntax accordingly but the debugger still highlights one line....

    Code:
    Dim rst As DAO.Recordset
    Set rst = Me!sfmY.Form.RecordsetClone
    rst.MoveFirst
    Select Case Me!sfmY.Form![IDbis]
    Case rst!Me!sfmY.Form![IDbis]             'highlighted by debugger
            Me!sfmY.Form.[ctrl1].Visible = False
            Me!sfmY.Form.[ctrl2].Visible = False
    Case Else
            Me!sfmY.Form.[ctrl1].Visible = True
            Me!sfmY.Form.[ctrl2].Visible = True
    End Select
    rst.Close
        Set rst = Nothing
    Any hint ?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    "Me" provides a way to refer to the specific instance of the class where the code is executing. In this case, "ME" refers to "Forms!frmX" (per your exampel).
    So you cannot have "rst!Me!sfmY.Form![IDbis]"

    Code:
    Dim rst As DAO.Recordset
    Set rst = Me!sfmY.Form.RecordsetClone
    rst.MoveFirst
    Select  Case Me!sfmY.Form![IDbis]  'looking at the subform, not the recordset
    Case rst!Me!sfmY.Form![IDbis] 'You cannot have "rst!" with "Me". this should be a value, ie when "Me!sfmY.Form![IDbis]" = 1, what should happen? when 2, whatshould happen?
            Me!sfmY.Form.[ctrl1].Visible = False
            Me!sfmY.Form.[ctrl2].Visible = False
    Case Else
            Me!sfmY.Form.[ctrl1].Visible  = True
            Me!sfmY.Form.[ctrl2].Visible  = True
    End Select
    rst.Close
        Set rst = Nothing
    example of case syntax
    Code:
    Select  Case Me!sfmY.Form![IDbis] 
    Case 1 to 5
            Me!sfmY.Form.[ctrl1].Visible = False
            Me!sfmY.Form.[ctrl2].Visible = False
    Case 10
            Me!sfmY.Form.[ctrl1].Visible  = False
            Me!sfmY.Form.[ctrl2].Visible  = True
     Case Else
            Me!sfmY.Form.[ctrl1].Visible  = True
            Me!sfmY.Form.[ctrl2].Visible  = True
    End Select
    I would like to apply conditional visibility to some controls on sfmY according to recordset position (basically, no visibility on first record and visibility on all other records).
    I don't think you can do what you want like this. There is no "first" in a recordset, it depends on how the recordset is sorted.

    You might investigate the "AbsolutePosition" property. There are a couple of examples under "See Also" ....

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

Similar Threads

  1. Show Recordset in unbound subform
    By vgarzon in forum Forms
    Replies: 4
    Last Post: 03-02-2011, 04:11 PM
  2. Filter recordset
    By jgelpi16 in forum Programming
    Replies: 2
    Last Post: 01-26-2011, 10:45 AM
  3. Using a string to DIM a Recordset
    By ColPat in forum Programming
    Replies: 10
    Last Post: 09-25-2010, 03:53 PM
  4. Replies: 1
    Last Post: 11-13-2009, 03:03 AM
  5. Show all recordset in form/subform
    By Brian62 in forum Forms
    Replies: 4
    Last Post: 11-04-2009, 11:56 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