Results 1 to 5 of 5
  1. #1
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40

    Can't Find my Form

    I am using the following code within a function to find a listbox count. It is called from a button on the frmReportSelection. It is not important what the surrounding code looks like, but it fails when it tries to find my form. The form name is frmReportSelection and it is a sub form of frmSCD. It always fails at the second line of code. Any suggestions?



    Code:
    Dim ListControl As Control
    Set ListControl = Forms!frmSCD!frmReportSelection!PickCGCRCounties
         With ListControl
     If .ListCount < 10 Then
        .ListRows = .ListCount
     Else
        .ListRows = 10
     End If
     End With
    Last edited by jeffhanner; 10-03-2022 at 10:43 PM. Reason: Clarification

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    What is name of the subform container control? I always name different from the object held, like ctrReport. Path must reference subform container control.

    Forms!frmSCD.ctrReport.Form.PickCGCRCounties
    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
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    jeffhanner is offline Advanced Beginner
    Windows 10 Access 2019
    Join Date
    Sep 2022
    Location
    Lincolln, CA
    Posts
    40
    Quote Originally Posted by June7 View Post
    What is name of the subform container control? I always name different from the object held, like ctrReport. Path must reference subform container control.

    Forms!frmSCD.ctrReport.Form.PickCGCRCounties
    Thank you for your information, however I couldn't get it to work that way. I finally just used:
    Set ctl = Me.PickCGCRCounties
    And that worked.


    Thanks for replying

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    So the code is actually behind the subform, not in a general module. I made an assumption that since you were trying to use the extended reference that code was in a general module. However, the full path should still work. Does for me.

    But since code is behind the subform, short path reference makes more sense.

    Why bother with the ListControl variable since code is behind the subform?

    Just:

    With Me.PickCGCRCounties
    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: 6
    Last Post: 04-16-2018, 09:15 PM
  2. Replies: 18
    Last Post: 08-02-2017, 12:56 PM
  3. Find Parent form name from called form
    By DrRob in forum Forms
    Replies: 2
    Last Post: 01-07-2016, 11:09 PM
  4. Replies: 7
    Last Post: 06-12-2012, 08:56 AM
  5. Replies: 9
    Last Post: 02-15-2011, 03:05 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