Results 1 to 3 of 3
  1. #1
    alberigo67 is offline Novice
    Windows 7 64bit Office 365
    Join Date
    May 2020
    Posts
    8

    Set focus to a user form the name of which is a variable

    Hi everyone.
    I have several user form opened and I need through VBA and some button to set focus to that forms the names of which are the contained in a variable. Each button set the variable with the name of the forms.
    I try something like this:

    Code:
    Dim FormAperto as New Form
    
    Set FormAperto.Name = VariableWithFormName
    
    FormAperto.SetFocus
    but it returns an error.
    I read that this kind of operation are not allowed with forms already opened. Is that true?



    Any ideas will be very appreciated.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,861
    That is not setting focus, but the name?

    The syntax would likely be Forms!FormName.SetFocus
    Not sure how you would get FormName replaced with variable though.

    I would expect you could open a form no problem with variable name as well.

    Edit: A quick Google found this?
    https://www.access-programmers.co.uk...riable.207392/
    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

  3. #3
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,643
    I'm confused Is this an excel userform or standard access form?

    Code:
    Set FormAperto.Name = VariableWithFormName
    What is the intent of this line?

    I read that this kind of operation are not allowed with forms already opened. Is that true?
    You cannot set focus to a form unless it is open.

    Do you want something like
    Code:
    Forms(VariableWithFormName).setFocus
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

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

Similar Threads

  1. Pass variable from user input to query
    By jmichaels in forum Modules
    Replies: 2
    Last Post: 04-10-2020, 05:45 AM
  2. Replies: 3
    Last Post: 10-30-2013, 05:59 AM
  3. MakeTable Query with Variable user defined Name
    By Dinzdale40 in forum Programming
    Replies: 1
    Last Post: 03-09-2011, 11:26 AM
  4. User focus control in AfterUpdate event
    By nosliwmada@gmailcom in forum Programming
    Replies: 3
    Last Post: 12-20-2010, 12:51 PM
  5. Replies: 1
    Last Post: 12-21-2005, 12:27 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