Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936

    Set focus to another form

    I have tried everything posted but nothing seems to be working. This seems such a simple task.

    Situation: open database, show main form, open second form, bring second form to the fore.

    This is the sequence of events according to MS.

    Open Load Resize Activate Current

    In On Current of the main form I have:
    DoCmd.OpenForm formx (variable)
    Forms(formx).SetFocus

    I tried putting the actual form name instead of the variable but that didn't work either. Any help will be greatly appreciated.

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    if you want to set focus on a form you can use its fully qualified name to access the SetFocus method.

    Forms!FormName.SetFocus

    However, the following line should open the form and set focus on that form
    DoCmd.OpenForm "FormName"

  3. #3
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Thanks for responding.

    I tried using the fully-qualified name, still didn't work.

    I already have the DoCmd.Openform statement, that does not set the focus on the form either.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by aytee111 View Post
    ...I already have the DoCmd.Openform statement, that does not set the focus on the form either....
    Those are the two methods I use. However, forms do not always have the capability to receive focus. Perhaps there is a control in your form that is capable of receiving focus. However, you should get a runtime exception if there is not a capability to setfocus on the form or a control. Make sure you are not using a modal property = True on an open form.

    Code:
    DoCmd.OpenForm "FormName"
    Forms!FormName!ControlName.SetFocus

  5. #5
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    I have replicated my problem here, maybe you can see what I am doing wrong.
    Attached Files Attached Files

  6. #6
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    You have to put code in the event click on the button.
    Code:
    Private Sub Command1_Click()
        DoCmd.OpenForm "Form2"
        Forms!Form2!text1.SetFocus
    End Sub

  7. #7
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The form doesn't have a button to click on - that is what I am trying to accomplish, no button, automated opening of form 2.

  8. #8
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528
    Mark event in Timer

  9. #9
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry, don't get that. This must only happen when the database is first opened, I don't want to set a timer event that will continually be running, if that is what you are suggesting?

  10. #10
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Posts
    528

    See this example

    See this example
    Attached Files Attached Files

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by aytee111 View Post
    Sorry, don't get that. This must only happen when the database is first opened, I don't want to set a timer event that will continually be running, if that is what you are suggesting?
    If you want a form to open when the database is opened you can select the name of the form within the database's options. Click on the File tab within the Ribbon and click 'Options'. The 'Access Options' window will open. Under 'Current Database', select the correct form name for the 'Display Form:' option.

  12. #12
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Thanks for your examples. The two choices you gave me are to (1) have a timer running continuously or (2) make the second form a popup. Neither of those fit in with what I am trying to do. I cannot believe that this is not possible, to give another form the focus, a plain and simple form, without going through these hoops. I told the user that I could open the database to the form they use the most, saving them going through the main screen every time, without closing the main form and without forcing them to stay there (which is what the popup does).

    Like I say, a simple enough request yet impossible to accomplish!

  13. #13
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It is not clear to me what you are trying to accomplish. If you need to open a second form when the application opens, I would place vba in the Default Form's On Load event.
    DoCmd.OpenForm "FormName"

  14. #14
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2010 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry for not explaining myself properly. The database that I attached earlier is how mine is set up: open form1, form2 opens automatically and brought to the front - that last part is what is not happening, form1 is still the one in front.

  15. #15
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    OK, I see what you want and why it is happening the way it is. I suppose using the timer of Form1 is an option. I would set From2 as the Default form to open and place the following in the On Load of Form2.
    Code:
    DoCmd.OpenForm "Form1"

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-24-2015, 11:29 AM
  2. Set focus in sub form
    By Derrick T. Davidson in forum Forms
    Replies: 7
    Last Post: 08-15-2014, 08:18 AM
  3. Set focus in other form?!!!
    By zareh in forum Forms
    Replies: 4
    Last Post: 02-27-2014, 02:33 AM
  4. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  5. Replies: 11
    Last Post: 01-26-2012, 01:22 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