Solved

Using equations in access

Posted on 2006-11-13
6
917 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

813 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

14 Experts available now in Live!

Get 1:1 Help Now