473,434 Members | 1,458 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,434 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 33714
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.