Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using equations in access

Posted on 2006-11-13
6
Medium Priority
?
924 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 66

Accepted Solution

by:
Jim Horn earned 1600 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 66

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 66

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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