Results 1 to 6 of 6
  1. #1
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181

    Using variable form name in form controls

    I am having controlling the master form from a subform. The subform will be used across several master forms, so it is important for the master form to have a variable name. I've successfully figured out how to set the textbox txtMasterFormName in the subform to the appropriate value. I'd like to use the value in the textbox to reference the master form, and make another subform visible.



    Code:
    Private Sub Label10_Click()
    Dim MasterFormName As String
    
    'For example, let's say txtMasterFormName = frm05LoginLandingPage.  That is an existing form that is spelled correctly
    MasterFormName = Me.txtMasterFormName.Value
    
    Forms(MasterFormName).SetFocus
    
    Forms!MasterFormName!frm071UploadPopUp.Forms.Visible = True
    'Intended output should be Forms!frm05LoginLandingPage!frm071UploadPopUp.Forms.Visible = True
    
    End Sub
    I am getting the error "Microsoft Access cannot find the referenced form 'MasterFormName'"

    Any help?

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Since your SubForm seems to always be referencing the MainForm to which it is a SubForm, why not just use the Me.Parent syntax?

  3. #3
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    I didn't know that syntax existed. Thanks!

    Unfortunately I don't think I used it properly:

    Code:
    Private Sub Label10_Click()
    Me.Parent.frm071UploadPopUp.Forms.Visible = True
    End Sub
    Error: "Object doesn't support this property or method."

  4. #4
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    try me.parent.form.visible

  5. #5
    kagoodwin13 is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Feb 2012
    Posts
    181
    Solved it:

    Code:
     Me.Parent.frm071UploadPopUp.Visible = True
    It was the .Forms part throwing Access off.

    Thanks for getting pointing me the right way!

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success and solution and marking this thread as Solved.

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

Similar Threads

  1. Replies: 5
    Last Post: 04-27-2015, 02:40 PM
  2. Replies: 8
    Last Post: 01-13-2015, 12:23 PM
  3. Replies: 1
    Last Post: 03-28-2013, 07:54 AM
  4. Refering to variable form names inside a variable
    By redpetfran in forum Programming
    Replies: 2
    Last Post: 05-21-2010, 01:39 PM
  5. Replies: 1
    Last Post: 04-13-2010, 12:18 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