Results 1 to 6 of 6
  1. #1
    Join Date
    May 2012
    Posts
    132

    Unanswered: VBA code of a button

    I have inserted a button on the form to save the form data on a table. I did this through the “command button wizard”. I would like to know if there is an equivalent VBA code which performs the same, ie. Saves the data and goes to the next record, just like what is done in macro.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Thought I was losing it, then realized that I had answered the same question on another forum! But I'll post the answer here, too.

    Assuming that this is a Bound Form, as it really should be, for entering Records in in Access, the Record is automatically Saved when you either Move to another Record, Close the Form or Close Access itself. So you simply need to Move to the next Record, which can be done with

    DoCmd.GoToRecord , , acNext

    To Move to a New Record it would be

    DoCmd.GoToRecord , , acNewRec

    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

  3. #3
    Join Date
    May 2012
    Posts
    132
    thank you linq,
    well, it seems to me that the "new record" is also "the next record" and vise versa. is this right? so do we only need to put either of these codes?

  4. #4
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    It depends! The 'Next Record' is only a 'New Record' if the 'Current Record,' i.e. the one being worked on when the Button is clicked, is either a 'New Record' itself or the 'Last Record' currently on the Form.

    In other words, if you're on existing Record #100 on a Form, and the Counter says Record 100 of 150, and you go to the 'next' Record, that will be Record #101.

    But if you're on existing Record #150 on a Form, and the Counter says Record 150 of 150, and you go to the 'next' Record, that will be both the 'Next Record' (# 151) and a 'New Record.'

    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

  5. #5
    Join Date
    May 2012
    Posts
    132
    Thank you,
    Does this mean that if we are working on the last record, through a form from example, either of the mentioned codes will suffice to move to both next and new record?

  6. #6
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    That's correct/
    Hope this helps!

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

    All posts/responses based on Access 2003/2007

Posting Permissions

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