Results 1 to 5 of 5
  1. #1
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273

    GotFocus to open a form

    Hello,

    I'm working on a form (frmVisit) that users will fill out to request access for visitors. One control, txtZone, is for the user to select what level of access their visitor will need. What I would like to happen is when txtZone has the focus, frmZone, which is just a detailed description of the available zones, opens on the bottom half of the screen, and immediately sends the focus back to txtZone on frmVisit. When txtZone loses focus, the form would close. I've tried this with the following code...

    Private Sub txtZone_GotFocus()
    'Open frmZone for reference, and returns the cursor to the main form

    Dim strExp As String
    Dim strControl As String
    Dim strForm As String
    strExp = "frmZone"
    strForm = "frmVisit"
    strControl = "txtZone"


    'DoCmd.OpenForm strExp

    'DoCmd.SelectObject acForm, strForm
    'DoCmd.GoToControl strControl


    End Sub



    When I put the cursor on txtZone, all of the icons on the toolbar, the caption on frmVisit, and the writing on the bottom of the screen flash for about 10 seconds before the form opens. I'm assuming that when I add code for txtZone's LostFocus to close frmZone, things will really get ugly. I'm guessing there must be a better way to get this to work the way I want. Any suggestions?

    Thank you for your help.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    you dont have to say goto control,
    set the control.TABINDEX = 0 on the one want to be 1st.

  3. #3
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    One method I've used is to create a label with the required text. Initially, the Visible property is set to FALSE.
    In the GotFocus event, I set the Visible property to TRUE.
    In the LostFocus event, I set the visible property to FALSE.

  4. #4
    NISMOJim is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2010
    Posts
    273
    Making a label on the same form visible on GotFocus has worked great for me in the past also. Unfortunately, the detailed description of the different zones takes up too much screen space, and I don't want the form to be that large when the description is not displayed. I had an Open Form code on the after update property of the control before txtZone, and a Close Form on the one after, which worked ok, but after meeting with the people that are using the database, I see that they jump around a lot, and get frustrated when the description doesn't show up every time they're on that txtZone control. Are we out of options yet?

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You can have forms open but be hidden.
    Basically, the same process as a label.

    When form "frmVisit" opens, form "frmZone" opens at the same time, but hidden.

    Using "txtZone_GotFocus", make the form visible, "txtZone_LostFocus" makes the form hidden.

    Form "frmZone" would close when form "frmVisit" closes. Depends on the number of form you want to open hidden - its a memory thing...



    and the writing on the bottom of the screen flash for about 10 seconds before the form opens.
    I suspect the flashing is because you get into a loop. The code opens the form "frmZone", then sets the focus back to "txtZone", which then fires off the GotFocus event, which sets the focus to the form "frmZone", which then sets the focus to "txtZone", which .......

    Might be able to check to see if the form is loaded. If the form is already loaded, exit the sub.

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

Similar Threads

  1. Replies: 14
    Last Post: 09-15-2017, 11:25 AM
  2. Replies: 1
    Last Post: 03-02-2014, 01:31 PM
  3. Replies: 2
    Last Post: 08-07-2013, 07:44 AM
  4. Replies: 1
    Last Post: 05-03-2012, 02:25 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