Set subform visibile on specific criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OxfordConsult
    New Member
    • May 2007
    • 6

    Set subform visibile on specific criteria

    Hello,

    I need to know if in VB it is possible to set a subform that is visible sometimes and others invisible, to a selected record. For example on a separate Cmd click I have a separate form open up with the selected record. The code reads:

    DoCmd.OpenForm "frm_contactsEd it", , , "[ContactID]=" & Me.ListContact

    I need my visible comand to follow a similar procedure of setting to a specific record. It is not possible to link the subform and from because my form is not bound to any object.

    Any help would be appreciated.

    Oxford Consulting
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    Something like this in the After Update event of the list should work ...
    [CODE=vb]
    Private Sub ListContact_Aft erUpdate()
    If nz(DLookup("[ContactID]", "TableName" , "[ContactID]=" & Me.ListContact) ,"") = "" Then
    Me!SubformObjec tName.Visible = False
    Me!SubformObjec tName.Filter = ""
    Me!SubformObjec tName.FilterOn = False
    Else
    Me!SubformObjec tName.Visible = True
    Me!SubformObjec tName.Filter = "[ContactID]=" & Me.ListContact
    Me!SubformObjec tName.FilterOn = True
    End If

    End Sub
    [/CODE]

    Comment

    • bliddel
      New Member
      • Nov 2007
      • 2

      #3
      I tried this technique, using Access 2003 with SP3. Apparently the interpreter thinks that the subform name is the name of a field on the form. It throws an error message 2465, "Microsoft Access Cant find the field 'NameOfSubForm' referred to in your expression". Any other ideas anyone?
      Code:
      Private Sub SetVisibles()
          Select Case cboAssessType
              Case "G" ' General Education
                  Me!frmGenEdCoreReqs.Visible = True
              Case Else
                  Me!frmGenEdCoreReqs.Visible = False
          End Select
      End Sub

      Comment

      • bliddel
        New Member
        • Nov 2007
        • 2

        #4
        Never mind! Still part of the old school that think any time I am referring to a form, I need the Bang as the separator. Substituting the dot for the bang in my code worked just great!

        Comment

        Working...