Results 1 to 9 of 9
  1. #1
    Join Date
    Sep 2014
    Posts
    11

    Unanswered: Remove focus from a button when form opens

    Hi

    I am trying to prevent focus being on my first button when I open a form

    Is there a simple line of code for the form's 'On Open' event?


    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    you can set the focus to another control using .setfocus method. however whether you can do that in the on open event I don't know. not all events and methods are open for use in all event hooks, and offhand the form open event hook is one of the most restricted


    another approach is to open the form in design mode
    arrange the tab order accordingly so the item you don't want to have the order is down the list, and when you save the form make certain that same button doesn't have the focus. you should in any event have set your tab order appropriately for your users. for most of the world that means 'left to right, top to bottom', but if in your locale it should be 'bottom to top, right to left' set he tab order accordingly. setting tab orders can be a frightmare as Access re-interprets the order and the sequence that you change things can make life very tough to get the chanegs int he right order
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2014
    Posts
    11
    Thanks Healdem

    The form is bespoke Switchboard/Navigation so only has buttons and labels - I don't want the focus to be on anything

    Is there a SetFocus Is Null possibility and if so where would it go and what would it look like?

    Sorry to be a pain


    Hargo

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    I don't think you can actively NOT set the focus, it has to be set to something on the form. the form sets the focus to the first control it finds (whether thats the tab order or as a result of the last design change save.
    if it means that much to you then I'd suggest create a button which closes the form and set that as the default
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Sep 2014
    Posts
    11
    Thanks for getting back so promptly

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Alternately, you could use a 'sham control,' shrinking it to the size of a pinhead and setting focus to it when the Form opens:
    1. Place a Textbox on your Form
    2. Name it FauxControl
    3. Delete the attached Label
    4. Move the Textbox into the left, topmost portion of the Form Section
    5. Reduce the size of the Textbox to a pinhead
    6. Place the code below in the Form's Code Module

    Code:
    Private Sub Form_Load()
      FauxControl.SetFocus
    End Sub

    To do the same when moving to another Record, use the code in the Form_Current event, instead.

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  7. #7
    Join Date
    Sep 2014
    Posts
    11
    Thanks Missinglinq, worked a treat

    Don't suppose you could solve another problem for me could you?

    I have a Patient data entry form (PK NHS Number) and an Admissions data entry form (FK NHS Number)

    Admissions is NOT a subform of Patient due to its size (it uses tab control and has 3 pages)

    When Admissions opens I would like NHS Number from the Patient Form to Autofill NHS Number in Admissions and the focus to go straight to the next field (Patient ID - this is hospital reference)

    I have looked at various similar threads but they don't seem to be quite what I need

    (either that or I just don't have the VBA skills needed!!!)

    Thanks

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    new question new thread please..
    it helps you get answers, it helps others search for answers
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Sep 2014
    Posts
    11
    Okay thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •