473,836 Members | 2,084 Online
Bytes | Software Development & Data Engineering Community
+ 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 36202
1,278 Recognized Expert Top Contributor
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.

Aug 29 '13 #2
4 New Member

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
  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
5,501 Recognized Expert Moderator Expert

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
1,278 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?

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
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

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

Similar topics

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 using the following code with no luck: Private Sub Command3_Click() Dim Search As String, Message As String Search = "Find Program" Message = InputBox(Prompt, "Search") DoCmd.OpenForm "Programs", acNormal, , "Left(Program,10)...
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. This is what I have so far: Private Sub cmdadd_Click() Dim db As Database Dim rst As Recordset Dim strCriteria As String Dim intPointer As Integer
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 would rather just be able to click a button and copy it.
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 help me? for an example there is a "open" button in every programme...i want cord for "open" bitton thanks..
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 .Plz suggest me any body? Thanks & Regards Venkat
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 automatically send the worksheet via email to more than one recipient? I have searched and searched and tried different things. This is what I have tried but it didn't work. Under the command button's code: Dim Rcpts(1 to 3) As String Rcpts(1)...
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 those supplies. I also have a field on this form that is called Mission#. What I want to do is create a command button that will save those two fields only to another table. Is there a way to do this. I was also wondering if I can have this button...
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 DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70 Exit_Commandsaverecord_Click:
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 on the main form that I'm going to be using to submit the data. The main form is bound to a query, qryPatientDetail, and is filtered using a search form. The subform is currently linked to the main form with PatientDetailID as the Master and...
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 net.. the time interval property and the ontimer property = vbcode also done but none of them work.. please help me.. thanks
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
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 we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.