Solved

Using equations in access

Posted on 2006-11-13
6
915 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
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…

920 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

15 Experts available now in Live!

Get 1:1 Help Now