473,513 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding several fields in a form and storing in table?

Hi,

I am having some trouble with recording a [Total] field on a form into my Table after formatting it to calculate several fields on the form.
If i just put the amount in the [Total] field and have it linked to the correct field in my Table, it will record it. But not the other
if I have the field Total several others first.

Where am I going wrong?

TIA TORQUE
Mar 10 '06 #1
8 2161
"TORQUE" wrote
I am having some trouble with recording a
[Total] field on a form into my Table after
formatting it to calculate several fields on
the form. If i just put the amount in the
[Total] field and have it linked to the correct
field in my Table, it will record it. But not
the other if I have the field Total several
others first. Where am I going wrong?


If, as could be inferred from you post, you are storing a total along with
the values that are used to calculate it, your first "going wrong" is in
database design -- that is redundant, not normalized, and generally A Bad
Idea. On the other hand, if you are not going to store the factors, but only
keep track of the total in your DB, the design may be just fine.

Assuming the latter, what you have is called a calcuated Control, which
can't be bound to the data. But, what you can do is to include a Control on
your form, bound to the field where the daa is to be stored, with its
Visible property set to No. In the AfterUpdate event of any control that is
a factor in the calculation, you can copy the contents of the Calculated
Control into the invisible text box which will be stored/saved according to
the normal rules: when you move off the record to another, when you
explicitly request a save, when you close the form, and when you move from
the main form into a subform control.

Larry Linson
Microsoft Access MVP
Mar 10 '06 #2
On Fri, 10 Mar 2006 07:56:07 GMT, "Larry Linson" <bo*****@localhost.not> wrote:
"TORQUE" wrote
I am having some trouble with recording a
[Total] field on a form into my Table after
formatting it to calculate several fields on
the form. If i just put the amount in the
[Total] field and have it linked to the correct
field in my Table, it will record it. But not
the other if I have the field Total several
others first.

Where am I going wrong?


If, as could be inferred from you post, you are storing a total along with
the values that are used to calculate it, your first "going wrong" is in
database design -- that is redundant, not normalized, and generally A Bad
Idea. On the other hand, if you are not going to store the factors, but only
keep track of the total in your DB, the design may be just fine.

Assuming the latter, what you have is called a calcuated Control, which
can't be bound to the data. But, what you can do is to include a Control on
your form, bound to the field where the daa is to be stored, with its
Visible property set to No. In the AfterUpdate event of any control that is
a factor in the calculation, you can copy the contents of the Calculated
Control into the invisible text box which will be stored/saved according to
the normal rules: when you move off the record to another, when you
explicitly request a save, when you close the form, and when you move from
the main form into a subform control.

Larry Linson
Microsoft Access MVP


Hi Larry,
Thanks for you reply.

I have already created another field to do the calculations, and had it set to invisible, set the original [Total] field to look to it.
This part works fine, but it still doesn't save the resultof the [Total] field in my form, into my table. ????

Could you explain what you were talking about in your previous post?

Quote :

In the AfterUpdate event of any control that is
a factor in the calculation, you can copy the contents of the Calculated
Control into the invisible text box which will be stored/saved according to
the normal rules: when you move off the record to another, when you
explicitly request a save, when you close the form, and when you move from
the main form into a subform control.

I have no clue how to use the AfterUpdate, or any other events of the same type.

Thanks
Robert
Mar 10 '06 #3
Hi Torque

How are you doing the calculation for the value of the [Total]?
Somewhere along the line you have to have a final textbox in which you
put a value so that the value of [Total] can be calculated. In the
afterupdate event (Right-click textbox, Properties, event Tab, button
with 3 dots on the right of After update, code builder, ok) of the
final textbox you are going to put the following VBA:
Total.value = textbox1.value + textbox2.value * textbox3.value ...etc.
or whatever your calculation might be
How are you writing the data in the textbox to the table?

Mar 10 '06 #4
On 10 Mar 2006 13:37:57 -0800, "Hansen" <he******@hotmail.com> wrote:
Hi Torque

How are you doing the calculation for the value of the [Total]?
Somewhere along the line you have to have a final textbox in which you
put a value so that the value of [Total] can be calculated. In the
afterupdate event (Right-click textbox, Properties, event Tab, button
with 3 dots on the right of After update, code builder, ok) of the
final textbox you are going to put the following VBA:
Total.value = textbox1.value + textbox2.value * textbox3.value ...etc.
or whatever your calculation might be
How are you writing the data in the textbox to the table?

Hi Hansen

This is how I am writing the data in the textbox.
=[Drop1Pay]+[Drop2Pay]+[Drop3Pay]+[Drop4Pay]+[UndeckPay]+[ReDeckPay]+[DelayPay1]+[DelayPay2]+[DelayPay3]+[LayoverPay]

This works fine for the calculation, but it will not store the answer into the table.
Is there another way to do this calculation and have the calculation stored into the table?

TIA
Mar 10 '06 #5
Hi Torque

Is there a button on your form to write the values entered to the
table? If not, I suggest that you put one on the form and add the
record using the on click event of the button:

Example:

Dim dbs as DataBase
Dim rst as RecordSet
Dim qry as String

Set dbs = opendatabase()
qry = "Tablewheredatashouldbeadded"
set rst = dbs.openrecordset(qry, dbopendynaset)
With rst
.Addnew
!fieldnameintable = total.value
!fieldnameintable2 = textbox2.value ...etc
.Update
.close
End with

Mar 11 '06 #6
I don't know if I am allowed to do this but a good example of where you
can study this is:
http://www.blueclaw-db.com/unbound_access_forms.htm

Mar 11 '06 #7
On 10 Mar 2006 22:42:29 -0800, "Hansen" <he******@hotmail.com> wrote:
Hi Torque

Is there a button on your form to write the values entered to the
table? If not, I suggest that you put one on the form and add the
record using the on click event of the button:

Example:

Dim dbs as DataBase
Dim rst as RecordSet
Dim qry as String

Set dbs = opendatabase()
qry = "Tablewheredatashouldbeadded"
set rst = dbs.openrecordset(qry, dbopendynaset)
With rst
.Addnew
!fieldnameintable = total.value
!fieldnameintable2 = textbox2.value ...etc
.Update
.close
End with


************************************************** **
Hello again Hansen,

I have tried adding a button with the save record command, gone into the OnClick Event properties, this is what is there;

Private Sub Command153_Click()
On Error GoTo Err_Command153_Click
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command153_Click:
Exit Sub

Err_Command153_Click:
MsgBox Err.Description
Resume Exit_Command153_Click

End Sub
I have tried many different variations of the example you gave me above and many times came up with errors. At times a lg box pops up
asking for a db or something. Other times no errors after clicking on the save button, but it does not record into table.

Maybe some info may help here.

my db name is newdb
the form im working in is named Table1
the table name is Table1
the 2 fields in particular im trying to record to Table1 are named, TripPay and TotalReimbursements
Im not real sure how to insert the info that you gave me above into the vb code screen.
If you want an idea of what im working with, I have posted 2 pics at this web address
http://home.carolina.rr.com/pcmed/

I have played around with access much in the past, but never had any instructions or help with it till lately.
I purchased a Training CD for Microsoft Access 2003 from http://www.vtc.com/. While this CD has been
very helpful, it is still not giving me some information that I am looking for. I do not work with Access on a
Professional Level, It's more for Personal fulfillment. I enjoy designing applications to help me in my
job field.

Thanks for your correspondence
Robert
Mar 11 '06 #8
Hi Torque

Does the Plus button on your form add all the data to Table1? How do
you record the other data on the form?
What you should do is replace the:

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

with: (and I don't know if what you named your textboxes)

Dim dbs as DataBase
Dim rst as RecordSet
Dim qry as String
Set dbs = opendatabase()
qry = "Table1"
set rst = dbs.openrecordset(qry, dbopendynaset)
With rst
.Addnew
!TripPay = trippay.value (if trippay is what the name of the
textbox is)
!TotalReimbursements = Taxi.Value + Tolls.Value + ATM.Value +
Fuel.Value + Misc.Value
.Update
.close
End with

There are numerous other considerations to take into account here.
Is the TripNumber unique or the Primary Key?
Are you checking if you are duplicating data?
Which record are you adding the totals to?

If you want to, Zip or rar your db and e-mail it to me and I will
change it and document for you how to change it.

Mar 12 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1412
by: nt9 | last post by:
I am very new with php so excuse me please if the question seems really easy.I have a page(form) which displays a list of the titles of some books(retreived from a database) and each title has a...
3
2430
by: mark | r | last post by:
ok, so i now know how to add, edit, delete and search for products (havent figured out categorisation out yet tho) - how do i upload an image and save the file name to the database as part of the...
5
3727
by: Sami | last post by:
Please bear with me, and if you answer this question, please do it step by step. I am new at Access, not at all sophisticated. I am using Office XP. This will need to be read in Access for...
4
4529
by: Erik Thorsen | last post by:
I need help with a tricky questions which I belive have a simple solution? For those who know Nwind.mdb, the example database that comes with microsoft access, it has several different tables. One...
5
6090
by: ND | last post by:
I need to create a separate field from 4 fields, "street address", "city", "State" and "zip code". For example, Street address - 100 Forest Street City - Seattle State - WA Zip - 05555 ...
3
2112
by: MS | last post by:
What's the best way to "store" and display a value in a text box that changes from day to day. An example of this would be where the name of the user is manually typed in after using the datbase,...
0
316
by: TORQUE | last post by:
Hi, I am having some trouble with recording a field on a form into my Table after formatting it to calculate several fields on the form. If i just put the amount in the field and have it linked...
1
2002
damonreid
by: damonreid | last post by:
Access 2003 Microsoft Windows XP Pro Hey, I am currently pulling my hair out here. I have a Form for adding new projects to a database, the only problem is that when I close the form it doesn't...
1
4879
by: swethak | last post by:
Hi, I am desiging the calendar application for that purpose i used the below code. But it is for only displys calendar. And also i want to add the events to calendar. In that code displys the...
0
7260
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
7162
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
7539
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
7527
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
5686
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,...
1
5090
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
4746
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
3223
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
456
bsmnconsultancy
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...

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.