Results 1 to 13 of 13
  1. #1
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123

    Open a Form up to a specific field

    Hi, I've been trying to fool around with having certain Forms open to a certain field for data to be entered. The Form's is, 'Daily_Music_Log_frm' & the field's name is 'DayTime'

    Here's the code I tried:


    Private Sub DayTime_Click()


    On Error GoTo Err_DayTime_Click



    DoCmd.GoToRecord , , acNewRec
    Forms![Daily_Music_Log_frm].DayTime.SetFocus


    Exit_DayTime_Click:
    Exit Sub


    Err_DayTime_Click:
    MsgBox Err.Number & ": " & Err.Description




    End Sub

    Any advice/suggestions will be greatly appreciated. Thanks in advance!

  2. #2
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Hi, I've been trying to fool around with having certain Forms open to a certain field for data to be entered
    I can't tell from that if the form is already open, or you are trying to open it from some other form, then move to a control. Your opening statement suggests one, your code the other. And is this all on a form with a datasheet and a header?

    If you're running code by clicking on a control, that control already has the focus, so it doesn't make sense to have code to set the focus to it.

  3. #3
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123
    Thanks for responding to my thread. Let's say I have a Datasheet Form with 6-fields:

    Field 1: xxx...
    Field 2: lll...
    Field 3: bbb
    etc.

    By default, the Datasheet Form will open up in Field 1, but how can I have the Datasheet Form to open/start in Field 3? Am I not making myself clear?

  4. #4
    Micron is offline Very Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    I've noticed that if I save and view a datasheet form, it doesn't seem to matter where I arrange the controls in design view after that - the order of the fields (columns) remains the same in datasheet view. I suspect the column layout is saved in a system table, so you will have to cause that to change. In datasheet view, move the column that is getting the focus to the position you want and it should work as you expect.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    Leave the code to open a New Record where it is, but move the Focus code to the Form_Current event for the Form.

    To always go to this Control when moving to a Record

    Code:
    Private Sub Form_Current()
      DayTime_Click.SetFocus
    End Sub
    To only do this when moving to a New Record

    Code:
    Private Sub Form_Current()
     If Me.NewRecord Then
      DayTime_Click.SetFocus
     End If
    End Sub

    Linq ;0)>

  6. #6
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123
    Hi, ling. Today, I backtracked searching to find anymore resolutions to my query & I missed yours. Although your second code in opening a New Record to a specific field looked exciting & promising, I cannot get it to work for me. I tried it several times on 2-different Forms & neither one worked. I was wondering if you might have any other ideas/suggestions?

    This may or may not help. I can open my Forms to a New Record with this code:

    Private Sub Form_Load()
    DoCmd.GoToRecord , , acNewRec
    End Sub


    Yet I wish I could figure out how to open a New Record in a specific field/control; that wold be ideal. I don't understand why your code aren't working?

    Anyway, thanks for responding to my thread & hopefully to hear back from you :-)

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Neither do I. The code works for me.

    Could try setting TabOrder property.

    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.

  8. #8
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123
    Ok, my objective is to have my cursor start in a specific field/control in 2-different Forms:

    Form 1: Music_Entries_frm [AtistID]

    Form 2: Music_Daily_Log_Entries [Datime]

    *Note Both Forms should open upon opening dbs. And, I have Access 2016, but you have Access 2010. I'm not sure how to send you my dbs?
    Attached Files Attached Files

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Db opens just fine. Two forms open. There is no code to set focus.

    Interesting, TabOrder property worked for me in my db for Datasheet view but not working in yours. It does work for Single or Continuous views. Same goes for VBA.

    Me.ArtistsIDcbx.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.

  10. #10
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123
    June, thanks for your time. One question, if you have a Form set to open up in Datasheet View) can you (or can you not) have it open in a particular field? If so, then how? If it's working on your dbs, why not send it back? Or, you made no changes, so what's the use.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    By my db, I mean MINE, not YOURS that I downloaded.

    I tested a form in datasheet view in MY db for the TabOrder property and VBA code - both work (with TabOrder set at 0 for a control, that 'column' shows as the first one).

    When I did these same tests in YOUR downloaded db, did not work for datasheet view. I am totally baffled as to why.

    So, change your form to Single or Continuous view and see what happens with TabOrder and code.
    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
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664

    Question

    Very Strange.

    I added set focus commands to the On Load events of both forms and both forms open to a new record with the focus set to the required controls.

  13. #13
    djclinton15 is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Nov 2015
    Posts
    123
    Sorry Steve, I just got around to my email. Actually I spent all day working on dbs, but was able to Copy/Paste the codes on my (newer version dbs. Main thing I learned was that I needed to put the code in the 'On Load' uder the Event tab. That was what I was missing. Anyway, thanks a lot & much appreciation!

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

Similar Threads

  1. Close one form open another and set focus to a specific field
    By Derrick T. Davidson in forum Programming
    Replies: 12
    Last Post: 08-01-2014, 05:16 AM
  2. Replies: 1
    Last Post: 08-20-2013, 02:17 PM
  3. Open an external folder specific by a form field
    By AccessNoob16 in forum Forms
    Replies: 11
    Last Post: 04-09-2012, 01:30 PM
  4. Replies: 2
    Last Post: 08-11-2011, 10:02 AM
  5. Replies: 7
    Last Post: 11-29-2009, 01:44 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