473,396 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

access 97: function for multiplying numbers

Hello -
This should be an easy function to multiple all amounts if they
are negative values (< 0). however, i get an error message on the
db.openrecordset because it assumes that i want to count the number
of records that i have in the database. i just want to multiple the
myvalue by -1. what am i missing or doing wrong?
thanks in advance.

Dim db As Databases
Dim rst As Recordset
Dim I As Integer
Dim x As String
Dim MyValue

Set db = CurrentDb
'Set rst = db.OpenRecordset("tblBMOD-test")
MyValue = [Amount]

rst.MoveFirst
x = 0
Do Until rst.EOF
'multiply if MyValue is less than zero until all [ET Amount]
records are positive
'Integers need to be positive values.

If MyValue > 0 Then
MyValue = MyValue * -1
End If
rst.MoveNext
Loop

MsgBox "Finished!! All amounts are positive values.", vbOKOnly
Nov 12 '05 #1
4 4067
On 28 Nov 2003 12:44:26 -0800, JMCN wrote:
This should be an easy function to multiple all amounts if they
are negative values (< 0). however, i get an error message on the
db.openrecordset because it assumes that i want to count the number
of records that i have in the database. i just want to multiple the
myvalue by -1. what am i missing or doing wrong?
thanks in advance.

Dim db As Databases
Dim db As Database 'remove the "s"
Dim rst As Recordset
Dim I As Integer
Dim x As String
Dim MyValue

Set db = CurrentDb
'Set rst = db.OpenRecordset("tblBMOD-test")
Set rst = db.OpenRecordset("tblBMOD-test", dbOpenDynaset)
(Quote removed, dynaset to enable updates).
MyValue = [Amount]
This line is useless here. See below.

rst.MoveFirst
x = 0
Do Until rst.EOF
'multiply if MyValue is less than zero until all [ET Amount]
records are positive
'Integers need to be positive values.

MyValue = [Amount] 'Inserted from above
If MyValue > 0 Then
If MyValue < 0 Then
MyValue = MyValue * -1
With rst
.Edit
![Amount] = MyValue
.Update
End With
End If
rst.MoveNext
Loop
rst.Close
Set rst = Nothing

MsgBox "Finished!! All amounts are positive values.", vbOKOnly


It would be faster this way:

Dim strSelect As String
strSelect = "UPDATE [tblBMOD-test] " & _
" SET [Amount]=[Amount]*-1 "& _
" WHERE [Amount]<0;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSelect
DoCmd.SetWarnings True
HTH - Peter

--
No mails please.
Nov 12 '05 #2
In addition to Peters response, you should look at the function Abs() which
returns the absolute value of a number so -5 becomes 5 etc.

--
Michael Hopwood (Phobos)
"JMCN" <pi******@yahoo.fr> wrote in message
news:27**************************@posting.google.c om...
Hello -
This should be an easy function to multiple all amounts if they
are negative values (< 0). however, i get an error message on the
db.openrecordset because it assumes that i want to count the number
of records that i have in the database. i just want to multiple the
myvalue by -1. what am i missing or doing wrong?
thanks in advance.

Dim db As Databases
Dim rst As Recordset
Dim I As Integer
Dim x As String
Dim MyValue

Set db = CurrentDb
'Set rst = db.OpenRecordset("tblBMOD-test")
MyValue = [Amount]

rst.MoveFirst
x = 0
Do Until rst.EOF
'multiply if MyValue is less than zero until all [ET Amount]
records are positive
'Integers need to be positive values.

If MyValue > 0 Then
MyValue = MyValue * -1
End If
rst.MoveNext
Loop

MsgBox "Finished!! All amounts are positive values.", vbOKOnly

Nov 12 '05 #3
no****@doering.org (Peter Doering) wrote in
<bq*************@ID-204768.news.uni-berlin.de>:
It would be faster this way:

Dim strSelect As String
strSelect = "UPDATE [tblBMOD-test] " & _
" SET [Amount]=[Amount]*-1 "& _
" WHERE [Amount]<0;"
DoCmd.SetWarnings False
DoCmd.RunSQL strSelect
DoCmd.SetWarnings True


If you're going to do it in code, then:

Dim db As Database

Set db = CurrentDB()
strSQL = [your SQL string]
db.Execute strSQL, dbFailOnError
Set db = Nothing

That way, you don't have to worry about SetWarnings.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #4
"Michael Hopwood" <la******@spammers.co.uk> wrote in message news:<u8********************@brightview.com>...
In addition to Peters response, you should look at the function Abs() which
returns the absolute value of a number so -5 becomes 5 etc.

--
Michael Hopwood (Phobos)


thank you all for your advice! i forgot about the absolute function,
actually i have never used it and it worked well!!
thanks again! jung
Nov 12 '05 #5

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

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Craig | last post by:
I am very new to access and I am trying to get a database set up to gather time data. Most, if not all of my data is in the nn:ss format or minutes and seconds. I am trying to set up a form to...
2
by: k | last post by:
I have aproblem when multiplying 2 float 638.9 * 382.8 should = 244570.92 results giving 244570.922 both numbers are float variables , tried using double to...
16
by: Martin Jørgensen | last post by:
Hi, Short question: Any particular reason for why I'm getting a warning here: (cast from function call of type int to non-matching type double) xdouble = (double)rand()/(double)RAND_MAX;
74
by: lovecreatesbeauty | last post by:
My small function works, but I have some questions. And I want to listen to you on How it is implemented? 1. The function does not check if parameter x is larger or smaller than parameter y. ...
32
by: chris.fairles | last post by:
Just want an opinion. I have an algorithm that needs to run as fast as possible, in fact. Its already too slow. I've done as much algorithmic changes as I can to reduce the amount of code, so now...
5
by: effendi | last post by:
I am trying to write a simple routine multiplying one value of a field to another. i.e cost1 multiple by cost2.. But since I have many lines of these, I want to write a function by accessing the...
9
by: Cogito | last post by:
I would like to calculate factorial numbers that produce results of say 100 digits. What is the best way of doing it in Javascript? Can I define a variable and somehow have control on each of its...
0
by: Dipanwita | last post by:
I have written a RSA encryption/decryption function in c using the formula a = b^c %n. For solving the equation I have used Squaring and multiplying method for modulo exponentiation . These...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.