Results 1 to 4 of 4
  1. #1
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67

    Referencing an open form by name from code not in the forms codefile

    I am trying to create a routine that opens a form at a specific location. I have



    Sub OpenForm(Name$, Left_, Top_)
    DoCmd.OpenForm Name$
    If (Left_ <> 0) Or (Top_ <> 0) Then
    Forms!Name$.Move Left_, Top_
    End If
    End Sub

    Sub Test02()
    OpenForm "Form2", 1000, 1000
    End Sub


    Every time I run Teso02 I get an error msg saying that there is no form named Name$.

    I realize one workaround would be to use global variables

    Public FormTop as Integer, FormLeft as Integer and get

    Sub OpenForm(Name$, Left_, Top_)
    FormLeft = Left_
    FormTop = Top_
    DoCmd.OpenForm Name$

    End Sub


    and put the following in the codefile of Form2 and all other forms


    Private Sub Form_Load()
    If (FormTop <> 0) or (FormLeft <> 0) then
    Me.Move FormLeft, FormTop
    EndIf
    End Sub

    But I suspect there's a way to reference the form whose name is contained in variable Name$ from code outside the form's codefile. If someone knows how to do this I'd appreciate hearing about it.

    Thanks in advance.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Try

    Forms(VariableName)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GeorgeJ is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    Dec 2014
    Posts
    67
    Thanks Paul. By now I shouldn't be surprised when I get from this forum a prompt reply which completely solves the issue.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  2. Replies: 2
    Last Post: 07-10-2013, 12:01 PM
  3. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  4. Referencing Controls on Forms
    By cbh35711 in forum Access
    Replies: 7
    Last Post: 04-05-2012, 09:04 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 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