Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command Button Code (A2k)

    Just can't seem to figure this out! I have a command button on a form, cmdAddARecord. What is the code that I need to set focus to the 1st control of next record??? Everything I've tried doesn't work.

    <img src=/S/help.gif border=0 alt=help width=23 height=15>

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button Code (A2k)

    It is a lot of work to let the code figure out what the first control is, so it's easier if you specify that yourself.

    Private Sub cmdAddARecord_Click()
    DoCmd.GoToRecord , , acNext
    Me.[txtSomething].SetFocus
    End Sub

    where txtSomething is the "first control".

    BTW, isn't cmdAddARecord a strange name for a button that takes you to the next record?

  3. #3
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button Code (A2k)

    >>BTW, isn't cmdAddARecord a strange name for a button that takes you to the next record?<<
    Perhaps I didn't articulate myself adequately.....I want the command button to take the user to the next blank record. Is the code still the same?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button Code (A2k)

    No, replace acNext by acNewRec.

  5. #5
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button Code (A2k)

    Ahhh, thanks Hans. Could you tell me what the commas are for in the code preceding acNext?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button Code (A2k)

    The complete syntax of GoToRecord is

    DoCmd.GoToRecord ObjectType, ObjectName, Record, Offset

    ObjectType can be for example acDataTable, acDataQuery and acDataForm; if you omit it, the action is performed on the active object type.
    ObjectName is the name of the object that the action will be performed on the active object.
    Record can be acFirst, acPrevious, acGoTo, acNext, acLast and acNewRec; if you omit it, acNext is assumed.
    Offset can only be used together which acPrevious and acNext to indicate the number of records to move, and with acGoTo to specify the record number to jump to.

    You can omit any of these arguments, but if you specify an argument after an omitted one, you must use commas.

    So DoCmd.GoToRecord , , acNewRec means that ObjectType and ObjectName are omitted, hence GoToRecord is applied to the active object (i.e. the form); we need to use two commas since we do specify Record. Offset is not appropriate here and since it comes at the end, it can be omitted entirely, no comma needed.

  7. #7
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button Code (A2k)

    You said this was gonna get easier! <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Command Button Code (A2k)

    <img src=/S/shocked.gif border=0 alt=shocked width=15 height=15> What??? You don't find this easy? <img src=/S/hushmouth.gif border=0 alt=hushmouth width=16 height=16>

  9. #9
    3 Star Lounger
    Join Date
    May 2003
    Location
    Sacramento, California, USA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command Button Code (A2k)

    <img src=/S/laugh.gif border=0 alt=laugh width=15 height=15> Ha Ha, Very funny--check out Scuttlebutt when you get a moment as I need a translation on a googlism-My last post there.

Posting Permissions

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