473,396 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Can I use a button on a form to save and go to new record at the same time on click?

I wrote this piece of code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandAddNew_Click()
  2. If Me.NewRecord Then
  3. DoCmd.RunCommand (acCmdSaveRecord)
  4. Else
  5. DoCmd.RunCommand (acCmdRecordsGoToNew)
  6. End If
  7. End Sub
  8.  
What I am really trying to do is use a single button to save the record and go to new record. Meaning when the user click the button, the record is saved and there is a new form to enter a new record.

How can I do this?


Thanks everyone!

SYN
Oct 3 '11 #1
2 33692
Well, I got the answer from the MS VBA forum, here is the code if anyone needs it!

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandAddNew_Click()
  2. If Me.NewRecord Then
  3. DoCmd.RunCommand (acCmdSaveRecord)
  4. DoCmd.RunCommand (acCmdRecordsGoToNew)
  5. End If
  6. End Sub
SYN
Oct 3 '11 #2
TheSmileyCoder
2,322 Expert Mod 2GB
Just to clarify something. As long as you are using recordsets, which Im sure you are, from what I see, you don't actively need to save the record. Moving between records forces a save in access. Thats standard behavior.

Also the button you have shown will only work if you are on a new record, but not if you are on an old record which you are simply editing.

To just go to a new record (and automatically save any changes) you can simply do:
Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandAddNew_Click()
  2.   DoCmd.RunCommand (acCmdRecordsGoToNew)
  3. End Sub
Oct 4 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

22
by: Br | last post by:
First issue: When using ADPs you no longer have the ability to issue a me.refresh to save the current record on a form (the me.refresh does a requery in an ADP). We usually do this before...
27
by: Kim Webb | last post by:
I have a field on a form for project number. I basically want it to be the next available number (ie 06010 then 06011 etc). In the form I create a text box and under control source I put: =!=...
3
by: kev | last post by:
Hi folks, I have a form for registration (frmRegistration) whereby i have two buttons. One is Save which saves record using the OnClick property. I used wizard to create the save button. The...
2
by: voroojak | last post by:
Hi How can i put save record and next record in one button. in my save record i put the calculation of the text boxes. i have a total field that the sum of the other field is in there and it wil be...
2
by: rockdc1981 | last post by:
I dont it is possible to put this codes together.. I want to prompt the user to save the record and at the same time have a log of audit trail. the codes work out fine separately. Code for Audit...
5
by: KingdomHeart | last post by:
I am very newbie in ajax, so please forgive me if my question are so dump. I want to create a box where user can type a message and when they click "Save" button. That text will be save. I got the...
20
by: Amanduh | last post by:
Hi, I'm kind of being forced to dive into the whole Access world at my work, and I haven't done coding in years. I've basically created the whole database I want, even made cascading comboboxes. ...
5
by: pld60 | last post by:
I have a bound form to a table. I have a command button to save when clicked that uses the following code. Private Sub Commandsaverecord_Click() On Error GoTo Err_Commandsaverecord_Click ...
4
by: TwoBit | last post by:
Hello Bytes, I am very new at using Microsoft Access and have just recently implicated it in recording productivity on outbound calls for my team. My team is in charge of making outbound calls...
1
by: Karan Singh Goyal | last post by:
I have an access table which have fields like Customer Id, First Name, Last Name etc. i know how to generate auto number but when i delete last record it generates next number instead of previous one...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.