Results 1 to 4 of 4
  1. #1
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194

    setting focus isnt working when closing a form back to another

    Wow i may as well live on this forum now!
    At least im starting to answer questions for people now with my basic knowledge

    Anyway i have a form [A] with fields [ONE] and [TWO]
    Then i have another form [B]

    When you type something in [ONE] and press enter, it sets focus to [TWO] (so that the text is 'saved' in [ONE]) then it opens new form [B]

    My issue is when i close [B] the focus still goes back to [TWO] but i want it go back to [ONE]

    I have tried

    !forms![A]![ONE].setfocus but it doesnt seem to work, it keeps going back to [TWO]



    My code for ON LOAD of [B]

    Code:
    If lstSuburb.ListCount = 0 ThenMsgBox ("No Suburb Found")
    Forms![ChemTrial]![SuburbID].Value = ""
    DoCmd.Close
    Forms![ChemTrial].SetFocus
    Forms![ChemTrial]![txtSuburb].SetFocus
    
    
    Exit Sub
    ideas? where am i going wrong?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Not seeing code that opens form [B].

    The code you posted is behind form [B]?

    Why set [SububID] to empty string? Is this an UNBOUND control for input of filter criteria?

    I would do something like:

    DoCmd.OpenForm "formB", , , , , acDialog
    Me.txtSuburb.SetFocus
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    gangel is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2014
    Posts
    194
    hey again June7,

    So this is behind [B].

    Chemtrial = [A] that i was using as an example .

    If someone looks up suburbs with their searchbox and no suburbs appear, its because their spelling is so wrong that there are no suburbs in the listbox filter.

    Therefore the [B] closes and goes back to [A] at the same place (txtsuburb] that the search started.

    The reason for the SuburbID= "" is that IF there was a suburb there (thus a bound id of...1) and then they search to change the suburb, if no suburb is found it removes the ID of 1, and changes it to null, as they dont have a suburb because searching for a new one deleted the current one.

    I have actually put docmd.cancelevent now which stops the cursur going to the next field

    This seems to work.

    I now just need it to select the text in [txtSuburb] in stead of just going to that box.!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:

    Me.controlname.SelLen = Len(Nz(Me.controlname, ""))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Bring back focus to a form
    By AbbHeDa in forum Programming
    Replies: 6
    Last Post: 04-28-2012, 01:50 AM
  2. DoCmd.OpenReport focus reverts back to form
    By shabbaranks in forum Programming
    Replies: 2
    Last Post: 01-07-2012, 06:18 PM
  3. Can anyone see why this isnt working please?
    By shabbaranks in forum Programming
    Replies: 3
    Last Post: 12-23-2011, 03:19 AM
  4. Setting focus on a tabbed form
    By crowegreg in forum Forms
    Replies: 21
    Last Post: 08-27-2011, 09:22 AM
  5. Setting Focus on a Form
    By MFeightner in forum Forms
    Replies: 1
    Last Post: 07-30-2009, 07:49 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