Solved

Using equations in access

Posted on 2006-11-13
6
914 Views
Last Modified: 2012-05-05
I guess this would be fairly easy for some one to answer, but is somewhat urgent.

If i have 2 txt boxes, 1 names txt1 other named txt2, I want to add the 2 values together or subract the 2 values, and then store the results for future use. How would i go abouts doing this?
0
Comment
Question by:CaptainGiblets
  • 3
  • 2
6 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 400 total points
ID: 17930154
How do you want to store the values?

In a variable...
Dim iTotal as Integer
iTotal = Nz(Me.txt1,0) + Nz(Me.txt2,0)

In another textbox, say txt3...
Me.txt3 = Nz(Me.txt1,0) + Nz(Me.txt2,0)

the Nz handles Nulls, in calse any of the txt's are blank
0
 
LVL 61

Expert Comment

by:mbizup
ID: 17930175
Hi CaptainGiblets,
the equation would be txt3 = txt1 + txt2

you can use a third textbox txt3 bound to the field you want to update, and use the after update events of txt2 and txt3,
 or use an update query:

Docmd.runsql "UPDATE Yourtable set Field1 = txt1+ txt2 Where {specify some condition}"

0
 
LVL 6

Author Comment

by:CaptainGiblets
ID: 17930802
so if i then had 20 different values from different txt boxes, how would i then go on to say.

if txt1 is not empty do this.

if txt2 is not empty do this.

etc and make sure users can only use numbers between 0-20 between these boxes.

sorry if this is going off topic a bit.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 65

Expert Comment

by:Jim Horn
ID: 17930864
You could also do stuff like this...

Dim x as Integer, lRunningTotal as Long
lRunningTotal  = 0

For x = 1 to 20
  DoSomethingWith = Nz(Me("txt" & x).Value,0)     '<--- Me("txt" & x) will loop from txt1 through txt20
  lRunningTotal  = lRunningTotal   &  Nz(Me("txt" & x).Value,0)
next

msgbox "txt 1 though 20 add up to " & lRunningTotal
0
 
LVL 6

Author Comment

by:CaptainGiblets
ID: 17931560
ok, also 1 more question regarding this matter.

once i have found my value

say sqlstr1 = 10

i then have a table called tbltest   and a column called   values      in 1 of these fields is the value 8

how would i add 10(sqlstr1) to this field.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 17931702
Execute a query that goes something like this...

UPDATE tblTest
SET [values] = [values] + sqlstr1
WHERE [values] = 8

btw if you have additional questions, it would be best to ask them as additional EE questions, instead of adding on to an already answered one.

0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now