Results 1 to 14 of 14
  1. #1
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43

    Setfocus to new record and directly be able to add text

    Hi guys,

    I have a button on a form which goes directly to a new record and focus on a field:

    Private Sub Button_Click()
    DoCmd.GoToRecord , , acNewRec
    Me.Customer.SetFocus
    End Sub

    It highlights the customer-field, but now I want to be able to type directly without clicking in the field.

    In another form I do the same with an field that has a value. There, It selects the tekst so I can change it directly.



    I searched and played around with some commands, but no luck.
    It should be easy. What am I doing wrong?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    The control has focus, start typing.

    Really shouldn't need the SetFocus code. Set the TabIndex property to 0 so the Customer control automatically has focus when moving to new record.
    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
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43
    Hi June7, Thanks for the reply

    Jou are right! But I can't directly start typing. I first have to click in the Customer field.

    I want to be able to click the button and directy start typing.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Well, it works for me. Cannot replicate issue.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  5. #5
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43
    ExampleSetFocus.zip

    In the ExampleSetFucus file I made a form with one button. This button has the Following code

    Private Sub Knop62_Click()
    DoCmd.GoToRecord , , acNewRec
    Custstr.SetFocus
    End Sub

    I want to be able to rype directly (without clicking) in the Custrstr field. How do I do this?

  6. #6
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Well now you have discovered one of the problems with split forms.
    You didn't mention that it was a split form before.

    You aren't getting any benefit from using a split form so simply use a data sheet version instead.

  7. #7
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43
    Ok thanks. But when a change to a datasheetview, my form header with menu is gone.

    I'm looking at the properties of the from, but I can't see the option to activate this?

  8. #8
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Ahh there is a problem - no header area in a datasheet.
    Couple of options - simply embed the datasheet into a sub form and put your controls around it, or
    Personally I would build a continuous form that looked like a datasheet.
    It gives you a lot more design and customisation flexibility in the long term, and allows you to fix column widths, stop people hiding columns then wondering where they've gone etc.

  9. #9
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43
    I have another access database with a split form. There I change a value and then a Afterupdate event kicks in.
    In this event there is an if else where it sets the focus on a field with a value. I can change the value directly.

    What could be the diffrence in this setfocus in a if-else? Is it possible to use this for the other split form?

  10. #10
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    Possibly, but if you are serious about getting your forms to be really functional, I would steer away from the split form.
    There are many gotcha's about them that will have you going round in circles trying to solve things that aren't solve-able because of they way they work (or don't depending on your view point).

    Just google "Access problem with split forms". And in almost every case the advice is to move away from them.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Just tested your code with a split form. It works. And with split form the SetFocus line is needed.
    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.

  12. #12
    dennisb82 is offline Advanced Beginner
    Windows 7 64bit Access 2016
    Join Date
    Aug 2017
    Posts
    43
    Nice! Is there a setting'I'm missing in my Access.
    It just highlights the field, but still I have to click to type in it.

    What do you mean with:

    Quote Originally Posted by June7 View Post
    And with split form the SetFocus line is needed.

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    Not aware of any setting. All I did was select a table in the Navigation Pane then select Split Form in the Create tab. Added a button and its code. Did not change any of the form properties.

    See post 2.
    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.

  14. #14
    Micron is offline Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,737
    The form control gets the focus and the cursor moves to the correct position within the control?
    You don't have a form keyboard event by chance? Wondering if the key press is running other code.
    Plus I don't get how the control can be highlighted if it's a new record. Something doesn't sound right about that, unless you have a default value there.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-26-2017, 02:09 PM
  2. Go Directly to a Form Record from a Report
    By stacynh in forum Forms
    Replies: 7
    Last Post: 05-15-2017, 07:54 AM
  3. Replies: 7
    Last Post: 06-05-2015, 11:13 AM
  4. Report only returns 1 record unless run directly
    By teresamichele in forum Reports
    Replies: 3
    Last Post: 12-17-2010, 12:06 PM
  5. Replies: 11
    Last Post: 07-20-2010, 06:55 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