Results 1 to 13 of 13
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Hide Unhide Subform By Selecting Account Title in Combo Box of Main Form

    I have 2 forms (Purchase and Purchase Subform)
    on purchase Form I have a combobox Cbottl

    What I want is when I select any title other than " *** Select Account Title ***" as this I have made a default value in the Combobox Cbottl. Only then the Purchase subform is shown otherwise it stays hidden.

    I have searched the forum and the net but I am unable to find the solution.

    I have attached a sample to give u an idea.



    Sample: Sample Database.zip

    Regards

    aamer

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Try If Then conditional code.

    The actually value of CboTtl is CoID but since combobox columns are actually text, try:

    If Me.CboTtl <> "1" Then
    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. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    If Me.CboTtl <> "1" Then
    Me.("purchase Subform").Visible = True
    Else
    Me.("purchase Subform").Visible = False
    End If


    Or What code should I write and where can u please explain in detail I mean on subform property or combo box

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    Where do you want it? Maybe in the combobox after update event?
    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.

  5. #5
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    If Me.CboTtl <> "1" Then
    Me.("purchase Subform").Visible = True
    Else
    Me.("purchase Subform").Visible = False
    End If

    I tried it in the combobox after update but its not working, giving errors.

    Also note, I already have

    Private Sub CboTtl_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[CoId] = " & Str(Me![CboTtl])
    Me.Bookmark = rs.Bookmark

    End Sub


    How can I have both in after update.

  6. #6
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    What is the exact error message?

    Private Sub CboTtl_AfterUpdate()
    Me.("purchase Subform").Visible = (Me.CboTtle <> "1")
    If Me.CboTtle <> "1" Then
    Dim rs As Object
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[CoId] = " & Str(Me![CboTtl])
    Me.Bookmark = rs.Bookmark
    End If
    End Sub
    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.

  8. #8
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I am getting Compile Error: Syntax Error

    Me.("purchase Subform").Visible = (Me.CboTtle <> "1")

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    I always give subform container control a name different from the object it holds, like ctrDetails.

    Me.ctrDetails.Visible = (Me.cboTtl <> "1")
    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.

  10. #10
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I have done all that u explained. but still getting error.

    I don't know what am doing wrong can u please check the attached DB to point out my mistake.


    thx


    Example Database.zip
    Last edited by aamer; 12-05-2014 at 11:17 PM.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    You have Purchases and Company tables linking on the CompanyName fields. Should be linking on the CoID and PurCoID fields. CompanyName field should not be in Purchases table.

    The subform Master/Child links should just be the CoID and PurCoID fields.

    I used ctrDetails as an example name. You did not use this as the name of your subform container. Use the name of your subform container in the code.

    Probably want to set the subform container Visible property to No. Then the code will make it visible after selection in combobox. However, I see no advantage to hiding/unhiding this subform.

    Advise not to use spaces or special characters/punctuation (underscore is exception) in naming convention.
    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.

  12. #12
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    The subform Master/Child links should just be the CoID and PurCoID fields. ------ Done
    What do u mean by subform container, This I don't understand
    are you saying I should put a text box on a subform and name it ctrDetails.

    I am totally lost here.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,643
    A subform/subreport is created by placing a subform/subreport container control on a form/report. Then its SourceObject property is set. If you drag a form from the navigation pane onto another form, this construction is not as apparent. The subform/subreport container control can be found on the Design tab when a form/report is in design view.
    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.

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

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2012, 10:53 AM
  2. Replies: 1
    Last Post: 05-23-2011, 07:11 AM
  3. Replies: 1
    Last Post: 01-10-2011, 12:25 AM
  4. Replies: 5
    Last Post: 01-02-2011, 10:09 AM
  5. Replies: 6
    Last Post: 06-03-2009, 02:01 PM

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