473,399 Members | 3,401 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,399 software developers and data experts.

Command button to save select fields in a form

17
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 set to close the form after it saves that info to the table.

Thanks for your help in advance.
Sep 20 '07 #1
5 2742
Scott Price
1,384 Expert 1GB
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 set to close the form after it saves that info to the table.

Thanks for your help in advance.
It sounds like you are intending to save a calculated result (Totals) in a table, is this right? This isn't a very good practice, as it consumes a lot of database overhead making the calculations, then saving, then re-calculating, then re-saving ad infinitum. It is a far better practice IMHO to make the calculations in a query, which is then available dynamically for any reporting, etc. that you wish to do.

Regards,
Scott
Sep 22 '07 #2
mdpems
17
The total will already post on the main form. What I want to do is save the total posted and the mission number it matches into another table. So basically all I want to save is just those two fields into another table.
Sep 24 '07 #3
Scott Price
1,384 Expert 1GB
If the table already exists you can run an append query from vba to insert the new records into the table. Otherwise you could also use a make table query from vba.

The general syntax of an append query is like this:
Expand|Select|Wrap|Line Numbers
  1. Dim MySQL As String
  2.  
  3. MySQL = "INSERT INTO tblIngredient(ItemName) VALUES (" & "'" & Me!txtFindAsUTypeValue & "'" & ");"
  4.  
  5. DoCmd.Setwarnings = False
  6. DoCmd.RunSQL MySQL
  7. DoCmd.Setwarnings = True
  8.  
  9. DoCmd.Close acForm, "tfrmHistory"
You will, of course have to change the names to reflect your table/field and form names... This can go into the on-click event of your command button.

Regards,
Scott
Sep 24 '07 #4
mdpems
17
For some reason I am still having problems with this code. I am getting a syntax error in the INSERT INTO line. I have changed the names with no results. I may have not been exactly clear on what I was trying to do. I have two tables in this data base with one form. On one table I have two columns labled Item and Cost for the supplies that we use per mission. I had to create a form with unbound text boxes labled patient names, date, mission number, and total. The total is calculated by selecting numerous items from a list box and multiplying them by cost and quantity. The second table I have for this form is called Supplies Total. This has two columns labled mission# and Total. What I want to do is create the one button that will save just those two fields only into the supplies total table. I think that the append query is on the right track but the code I tried wasn't working. I did get it to show an error one time stating that this was not an updateable query. Here is the code I inserted in VBA. The text14 is the name of mission number text box on the form. Thanks again for all the help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command32_Click()
  2. Dim MySQL As String
  3.  
  4. MySQL = "INSERT INTO [Supplies_Total](Mission#) VALUES (" & "'" & Me!Text14 & "'" & ");"
  5.  
  6.  
  7. DoCmd.SetWarnings False
  8. DoCmd.RunSQL MySQL
  9. DoCmd.SetWarnings True
  10.  
  11. DoCmd.Close acForm, "tfrmHistory"
Sep 24 '07 #5
Scott Price
1,384 Expert 1GB
For some reason I am still having problems with this code. I am getting a syntax error in the INSERT INTO line. I have changed the names with no results. I may have not been exactly clear on what I was trying to do. I have two tables in this data base with one form. On one table I have two columns labled Item and Cost for the supplies that we use per mission. I had to create a form with unbound text boxes labled patient names, date, mission number, and total. The total is calculated by selecting numerous items from a list box and multiplying them by cost and quantity. The second table I have for this form is called Supplies Total. This has two columns labled mission# and Total. What I want to do is create the one button that will save just those two fields only into the supplies total table. I think that the append query is on the right track but the code I tried wasn't working. I did get it to show an error one time stating that this was not an updateable query. Here is the code I inserted in VBA. The text14 is the name of mission number text box on the form. Thanks again for all the help.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command32_Click()
  2. Dim MySQL As String
  3.  
  4. MySQL = "INSERT INTO [Supplies_Total](Mission#) VALUES (" & "'" & Me!Text14 & "'" & ");"
  5.  
  6.  
  7. DoCmd.SetWarnings False
  8. DoCmd.RunSQL MySQL
  9. DoCmd.SetWarnings True
  10.  
  11. DoCmd.Close acForm, "tfrmHistory"
Two tables, one form. In the second table you want to add the totals?

Does it not work to use a query that combines the two tables into one record source for your form (making the calculations in the query), then bind the totals text box to the correct field in the second table?

As for the code, try using without the second set of "'" in other words: ...VALUES (" & Me!Text14 & ");"

Also, you'll have to remove the DoCmd.Close line (or change the form name from tfrmHistory, unless your form is also named tfrmHistory :-)

Regards,
Scott
Sep 25 '07 #6

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

Similar topics

5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
2
by: Rebecca | last post by:
I have a dynamically created command button on a .net page that adds 1 row to a sql server table when clicked. The page_load event load rows from that table for the user to view, but for some reason...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
2
by: Darren | last post by:
Hi, I have a command button which has a macro running in it. The macro on the click event, runs to ensure that certain values in a form are valid, (e.g. the textboxes are not null) and...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
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. ...
14
by: squrel | last post by:
Hello everyone, I m using some button using toolbar such as Add,Save,View,.... my save button is not working.... it doesnt give me any error but does not save to my database.... or showing in my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...
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
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...

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.