Results 1 to 5 of 5
  1. #1
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664

    Using the setFocus command on two forms at the same time

    Here is the text that describes how to use the setfocus command.




    Code:
    You can have VBA automatically move the cursor to any control on your form.
    This can be handy when your code can anticipate where the user is most likely
    to type next. You can have VBA position the cursor to the appropriate control
    automatically so that the user can just keep typing and not move the cursor
    on his own.
    
    The same technique also lets you avoid error messages caused by trying to
    disable (or hide or lock) the control that currently has the focus. The VBA
    syntax for setting the focus to a specific control is
    controlName
    .                                                               ControlName.SetFocus
    where 
    
    controlName is the name of the control to which you want to move
    the cursor. For example, the following statement moves the cursor to a control
    named 
    CCType on the form:
                                                                   [CCType].SetFocus
    



    What it does not tell you is how the command changes when the control is on a second form. Say you have two forms open and the cursor is at the bottom of the second one and you want it to go to the top of the first one.

    How is the command

    [CCType].SetFocus

    changed?

    Any help appreciated. Thanks in advance.

    Respectfully,

    Lou Reed



  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,642
    Try

    Forms!SecondFormName.DesiredControlName.SetFocus
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    2 separate forms,
    or
    1 master form,with a child form?

  4. #4
    Lou_Reed is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Posts
    1,664
    I am back on working on this and I think that maybe a master form and a child form might be the way to go. Is there any info written on this? I am unsure as to how to create the set.

    Respectfully,

    Lou Reed
    Last edited by Lou_Reed; 01-19-2017 at 12:14 PM. Reason: correction

  5. #5
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,511
    You have a main form based on a main table and a subform within that is based on the child table. They are usually linked by the Key field on the Main form and a Foreign key(same field) on the child table. This field would go into the LinkMaster and LinkChild properties on the Subform.

    But as pbaldy said, I believe if you want to set focus on a field in another form, use the full path or the form as he listed.

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

Similar Threads

  1. Add Command Button to Multiple Forms
    By jameslefebv in forum Forms
    Replies: 4
    Last Post: 07-14-2014, 07:07 PM
  2. Replies: 5
    Last Post: 01-16-2013, 03:48 PM
  3. Replies: 2
    Last Post: 07-24-2012, 12:44 PM
  4. VBA coding for forms and command buttons
    By bakerri2 in forum Access
    Replies: 1
    Last Post: 05-31-2012, 11:29 AM
  5. Command button for time & date
    By joet5402 in forum Forms
    Replies: 2
    Last Post: 12-20-2007, 02:59 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