473,473 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using a command button in a form to save & then open a new record

4 New Member
[z{mod-edit:Start of Original post}]
I wanted to have a Command Button on a form to save a record & then ask to open a new record. I am new to access.

I have MDFID on a form with primary key.

[z{mod-edit:Start of what was post 9}]

Thanks Seth,

To be frank, I wanted the save button to do the following:
1. Check if any fields are left blank.
2. If any fields are left blank then the button should not allow the user to save & prompt by giving message of the corresponding field which is left blank.
3. If all fields are filled then the button should save the record by enabling New Record button of a form (new record button should not be enable at the time of form entry).

Hope, I explained. Is it possible to do ?
Aug 29 '13 #1
10 36068
jimatqsi
1,271 Recognized Expert Top Contributor
tajuddin,
Your question leads me to think you might be best served with some of the lessons one can learn from the sample databases that come with Access. Under the Help menu you will find "Sample Databases." Explore those, they are very helpful for those who will invest sufficient time with them.

There is a wizard for adding a command button. The wizard can lead you through saving a record on a form, and many other useful tasks, in a very simple manner.

Jim
Aug 29 '13 #2
tajuddin
4 New Member
Jim,

Actually, i am using the below code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Save_Click()
  2. If IsNull(MDFDate) Then
  3. MsgBox ("Field 'Form Date' cannot be blank!"), vbOKCancel
  4. End If
  5.  
  6.  
  7. DoCmd.Save
  8. End Sub
I want save button to first save the record then prompt to open a new record "like do you want to enter new record".
Aug 29 '13 #3
Seth Schrock
2,965 Recognized Expert Specialist
What do you want to happen if the user doesn't want to enter a new record?

My preferred method of saving a record is
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdSaveRecord
To produce a messagebox that would go to a new record, you would use the following
Expand|Select|Wrap|Line Numbers
  1. Dim strMsg As String
  2. strMsg = "Do you want to enter a new record?"
  3. If MsgBox(strMsg, vbYes or vbQuestion) = vbYes Then
  4.     DoCmd.GoToRecord ,, acNewRec
  5. End If
Aug 29 '13 #4
zmbd
5,501 Recognized Expert Moderator Expert
tajuddin

Line 2: If IsNull(MDFDate) Then
I would change this to If (ME.MDFDate & "")="" Then
You will catch both the null state and empty string (there is no space between the double quotes).

Then follow Seth's advice.

Of Note:
If you are using either V2007 or V2010 you are better off not using the Control Design Wizards unless you will be publishing the database to Sharepoint.

Something that many people do not know is that MS has moved the default language for the Wizards from VBA to Macro. The two languages are not interchangable, and despite the improvements in Macro, VBA is still much more robust.

I also agree with jimatqsi. What you asked is covered in most of the basic tutorial sites and books. A foundational level of understanding of the basics would be most helpful for you and will make it much easier to understand our advice. :-D (please note, kind voice and BIG SMILE... we loose so much in the text)

Also, when posting Code/SQL/etc... or a table of data, please select the text and then click on [CODE/] formatting. :)
Aug 29 '13 #5
jimatqsi
1,271 Recognized Expert Top Contributor
I didn't know about that with the wizards and the "default language." Does that mean the language preference can be changed for the wizards?

Jim
Aug 30 '13 #6
Seth Schrock
2,965 Recognized Expert Specialist
I don't believe so Jim. That is why I never use those wizards anymore.
Aug 30 '13 #7
zmbd
5,501 Recognized Expert Moderator Expert
V2007 - there is a setting; however, buried.
V2010 - no, you can no longer change Control Wizards from Macro to VBA. Converting the Embeded macro from the wizard to VBA requires a multi step process... often easier to just write the code from scratch.
Aug 30 '13 #8
Seth Schrock
2,965 Recognized Expert Specialist
If you know of a way to convert a macro created by a wizard to VBA, please let me know. I have never been successful at doing this as the convert button is grayed out on these macros. I always have to create my own macro as a copy of the wizard's macro to be able to convert it.

Sorry for getting off topic. Maybe you could post an article about it and then delete this post.
Aug 30 '13 #9
Seth Schrock
2,965 Recognized Expert Specialist
Absolutely. In post #5, ZMBD gives the code to test for the fields being empty. You would just put your message about the fields being required in the true side of the If-Then-Else statement. In the False side, you would the save code that I posted in post #4 and then the enable the button, which is done with the following code:
Expand|Select|Wrap|Line Numbers
  1. Me.button_name.Enabled = True
You would probably want to set the NewRecord button's enabled property to false in the true side so that you can be sure of whether or not the button will have the proper enabled setting when you click the save button.
Aug 31 '13 #10
zmbd
5,501 Recognized Expert Moderator Expert
tajuddin:

We are not a code writing service. Several answers have been given and we'll help you if you get stuck implementing them; however, you really need to do the work... think of this as site that teaches how to fish so that you can eat everyday.

By way of helping yo learn the basics, this is a site that I've used off and on... not my favorite site due to the age now; however, the Basics are still solid.

Some things to note:
  1. - The following is old.
  2. - It is for Access95.
  3. - Many of the new features are not covered.
  4. - Much of the user interface has changed... not so much from V95 to V2003; however, from V95 to V2007/2010 that ribbon makes a muck of things until you learn where things were moved.
  5. - If you are using Access 2007/2010 ACCDB files then ignore the part about the switchboard (in fact, I ignored the switchboard after the first time I used it and the end users just about hung me [:(] )
  6. - It covers some neat tricks with the Macro Language... be leary of these... they do have their uses and I use some of these upon occation when nothing else will do the trick!
  7. - the Author is BIASED against VBA! Do not let his negative comments about VBA un-nerve you. What he doesn't cover there is covered in the online help documents and help is available here and elsewhere on the Net :D next to SQL, VBA is the biggest workhorse and most powerfull tool you have in the Access database.
  8. - I mention this here only because of the age of the site I'm sending you to: There was a change in the database model... from ADO to DAO back to ADO and now back to DAO... the default model in V2007/2010 is back to DAO. ADO is still there; however, many of us use it only if we'll be upsizing to larger database such as SQL-Server, MySQL, Oracle, etc.. (others swear by ADO over DAO... you can find that argument elsewhere and I'll delete any posts in this thread that attempt to start it as a hijack };-) )
]

MS Access 95 Tutorial
Aug 31 '13 #11

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

Similar topics

10
by: AccessHelp32 | last post by:
Hi All, I have a command button that opens an InputBox. I would like users to enter a string and have the InputBox open a Form and go to the record that matches the users string most closely. I'm...
9
by: rdade22 | last post by:
Hi, I'm new so try to bare with me. I'm using access 2000 and I created a database where the user is prompted to click on a command button and the info that was put on the form is sent to a table....
5
by: dgrabuloff | last post by:
i am inputting records using a form. how do i put a command button on the form that will copy the record i just input----sometimes i have the same record that needs to be put in 3 or 4 times and i...
4
by: sirimanna | last post by:
hi, Is any one can help me to open files in my computer(for an example: some word document)using command button... i want to open file's using my vb programme..but i can't do it...can any one...
2
by: tejavenkat | last post by:
Hi, I have one scenario i.e Download as csv is there it is a command button when we click on this the save dialog box should be open,Am using javascript how can we do this by using by javascrpt...
0
by: mesadobes | last post by:
I am very new to visual basic. Actually, I have no clue what I'm doing! But I know what I want to do. I am trying to learn as I go... How do I create a command button that when clicked will...
5
by: mdpems | last post by:
The organization I work for needs to use a form that we can send to a billing department that shows supplies we used and Mission#'s. I have a form to select supplies used and total the costs of...
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
beacon
by: beacon | last post by:
Hi everybody, I have a main form, frmDeficiency, that has a tab control, deficiencyTabControl, that has a subform, fsubEpisodeDetail, on page 2 of the tab control. I also have a command button...
1
by: marvinisla | last post by:
i am complete newbie in ms access 2007. I want to ask how to save unbound textbox value in a table using a command button? and also how to put a clock in a form. tried all the tutorial from the...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.