Connecting Tech Pros Worldwide Help | Site Map

access 2003: division operator problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 13th, 2005, 04:03 AM
JMCN
Guest
 
Posts: n/a
Default access 2003: division operator problem

hello
i am not getting the correct percentage results from the following
code. the "prelimpercent" variable = 0? why would that be the case
when i try to divide numrecs by numrecs2?

any advise would be appreciated. thanks in advance - jung
************************************************** ***********************

Dim rst, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs, numrecs2 As Integer
Dim percent, prelimpercent As Integer
Dim x As String

Set db = CurrentDb
'counts current records
x = Me![SQLStatement]
Set rst = db.OpenRecordset(x)
With rst
If rst.EOF = False Then
rst.MoveLast
numrecs = rst.RecordCount
Debug.Print numrecs '(19)
Else
numrecs = 0
End If
End With

'count records in qryAllOpenItems
Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
[Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
Erroneous Entry]=-1))))")
With rst2
If rst2.EOF = False Then
rst2.MoveLast
numrecs2 = rst2.RecordCount
Debug.Print numrecs2 '(74 records)
Else
numrecs2 = 0
End If
End With

prelimpercent = numrecs / numrecs2 '19/74
percent = prelimpercent * 100
Debug.Print percent

  #2  
Old November 13th, 2005, 04:03 AM
MGFoster
Guest
 
Posts: n/a
Default Re: access 2003: division operator problem

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Don't know if this is the solution, just saw it right-off:

Change this:

Dim rst, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs, numrecs2 As Integer
Dim percent, prelimpercent As Integer

to this:

Dim rst as DAO.Recordset, rst2 As DAO.Recordset
Dim db As DAO.Database
Dim numrecs As Integer, numrecs2 As Integer
Dim percent As Integer, prelimpercent As Integer

Variables dimmed w/o their data type default to Variants.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX
eYnPuUemIPGtXfXcSp6Xg4TJ
=Dukc
-----END PGP SIGNATURE-----


JMCN wrote:
[color=blue]
> hello
> i am not getting the correct percentage results from the following
> code. the "prelimpercent" variable = 0? why would that be the case
> when i try to divide numrecs by numrecs2?
>
> any advise would be appreciated. thanks in advance - jung
> ************************************************** ***********************
>
> Dim rst, rst2 As DAO.Recordset
> Dim db As DAO.Database
> Dim numrecs, numrecs2 As Integer
> Dim percent, prelimpercent As Integer
> Dim x As String
>
> Set db = CurrentDb
> 'counts current records
> x = Me![SQLStatement]
> Set rst = db.OpenRecordset(x)
> With rst
> If rst.EOF = False Then
> rst.MoveLast
> numrecs = rst.RecordCount
> Debug.Print numrecs '(19)
> Else
> numrecs = 0
> End If
> End With
>
> 'count records in qryAllOpenItems
> Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
> Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
> [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
> Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
> ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
> Erroneous Entry]=-1))))")
> With rst2
> If rst2.EOF = False Then
> rst2.MoveLast
> numrecs2 = rst2.RecordCount
> Debug.Print numrecs2 '(74 records)
> Else
> numrecs2 = 0
> End If
> End With
>
> prelimpercent = numrecs / numrecs2 '19/74
> percent = prelimpercent * 100
> Debug.Print percent[/color]

  #3  
Old November 13th, 2005, 04:03 AM
MacDermott
Guest
 
Posts: n/a
Default Re: access 2003: division operator problem

You have declared prelimpercent as an integer -
so it will round any value less than .5 to 0.

HTH
- Turtle

"JMCN" <picarama@yahoo.fr> wrote in message
news:2772ee20.0411011229.3f024292@posting.google.c om...[color=blue]
> hello
> i am not getting the correct percentage results from the following
> code. the "prelimpercent" variable = 0? why would that be the case
> when i try to divide numrecs by numrecs2?
>
> any advise would be appreciated. thanks in advance - jung
> ************************************************** ***********************
>
> Dim rst, rst2 As DAO.Recordset
> Dim db As DAO.Database
> Dim numrecs, numrecs2 As Integer
> Dim percent, prelimpercent As Integer
> Dim x As String
>
> Set db = CurrentDb
> 'counts current records
> x = Me![SQLStatement]
> Set rst = db.OpenRecordset(x)
> With rst
> If rst.EOF = False Then
> rst.MoveLast
> numrecs = rst.RecordCount
> Debug.Print numrecs '(19)
> Else
> numrecs = 0
> End If
> End With
>
> 'count records in qryAllOpenItems
> Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
> Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
> [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
> Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
> ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
> Erroneous Entry]=-1))))")
> With rst2
> If rst2.EOF = False Then
> rst2.MoveLast
> numrecs2 = rst2.RecordCount
> Debug.Print numrecs2 '(74 records)
> Else
> numrecs2 = 0
> End If
> End With
>
> prelimpercent = numrecs / numrecs2 '19/74
> percent = prelimpercent * 100
> Debug.Print percent[/color]


  #4  
Old November 13th, 2005, 04:03 AM
Damien
Guest
 
Posts: n/a
Default Re: access 2003: division operator problem

[re-arranged for readability, bottom posting]
[color=blue]
> JMCN wrote:
>[color=green]
> > hello
> > i am not getting the correct percentage results from the following
> > code. the "prelimpercent" variable = 0? why would that be the case
> > when i try to divide numrecs by numrecs2?
> >
> > any advise would be appreciated. thanks in advance - jung
> > ************************************************** ***********************
> >
> > Dim rst, rst2 As DAO.Recordset
> > Dim db As DAO.Database
> > Dim numrecs, numrecs2 As Integer
> > Dim percent, prelimpercent As Integer
> > Dim x As String
> >
> > Set db = CurrentDb
> > 'counts current records
> > x = Me![SQLStatement]
> > Set rst = db.OpenRecordset(x)
> > With rst
> > If rst.EOF = False Then
> > rst.MoveLast
> > numrecs = rst.RecordCount
> > Debug.Print numrecs '(19)
> > Else
> > numrecs = 0
> > End If
> > End With
> >
> > 'count records in qryAllOpenItems
> > Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
> > Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
> > [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
> > Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
> > ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
> > Erroneous Entry]=-1))))")
> > With rst2
> > If rst2.EOF = False Then
> > rst2.MoveLast
> > numrecs2 = rst2.RecordCount
> > Debug.Print numrecs2 '(74 records)
> > Else
> > numrecs2 = 0
> > End If
> > End With
> >
> > prelimpercent = numrecs / numrecs2 '19/74
> > percent = prelimpercent * 100
> > Debug.Print percent[/color][/color]

MGFoster <me@privacy.com> wrote in message news:<hjxhd.1178$O11.749@newsread3.news.pas.earthl ink.net>...[color=blue]
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Don't know if this is the solution, just saw it right-off:
>
> Change this:
>
> Dim rst, rst2 As DAO.Recordset
> Dim db As DAO.Database
> Dim numrecs, numrecs2 As Integer
> Dim percent, prelimpercent As Integer
>
> to this:
>
> Dim rst as DAO.Recordset, rst2 As DAO.Recordset
> Dim db As DAO.Database
> Dim numrecs As Integer, numrecs2 As Integer
> Dim percent As Integer, prelimpercent As Integer
>
> Variables dimmed w/o their data type default to Variants.
>
> --
> MGFoster:::mgf00 <at> earthlink <decimal-point> net
> Oakland, CA (USA)
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGP for Personal Privacy 5.0
> Charset: noconv
>
> iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX
> eYnPuUemIPGtXfXcSp6Xg4TJ
> =Dukc
> -----END PGP SIGNATURE-----
>
>[/color]

What you didn't spot is that he's storing his prelimpercent (a number
between 0 and 1) into an INTEGER - which can only be 0 or 1, and so
the result will always be either 0% or 100%, after the multiplication.

Option 1) Store the prelimpercent into a Double,

Option 2) Multiply numrecs by 100 BEFORE doing the division.

Either will work, whatever floats your boat really (although,
obviously, if you want fractional percentages, option 1 is the way to
go).

Damien
  #5  
Old November 13th, 2005, 04:04 AM
JMCN
Guest
 
Posts: n/a
Default Re: access 2003: division operator problem

thank you for your advise! i realized that after writing it that i
should have declared the prelimpercent as double!

thanks again!!!! jung

Damien_The_Unbeliever@hotmail.com (Damien) wrote in message news:<ac70a9d9.0411012342.281f6204@posting.google. com>...[color=blue]
> [re-arranged for readability, bottom posting]
>[color=green]
> > JMCN wrote:
> >[color=darkred]
> > > hello
> > > i am not getting the correct percentage results from the following
> > > code. the "prelimpercent" variable = 0? why would that be the case
> > > when i try to divide numrecs by numrecs2?
> > >
> > > any advise would be appreciated. thanks in advance - jung
> > > ************************************************** ***********************
> > >
> > > Dim rst, rst2 As DAO.Recordset
> > > Dim db As DAO.Database
> > > Dim numrecs, numrecs2 As Integer
> > > Dim percent, prelimpercent As Integer
> > > Dim x As String
> > >
> > > Set db = CurrentDb
> > > 'counts current records
> > > x = Me![SQLStatement]
> > > Set rst = db.OpenRecordset(x)
> > > With rst
> > > If rst.EOF = False Then
> > > rst.MoveLast
> > > numrecs = rst.RecordCount
> > > Debug.Print numrecs '(19)
> > > Else
> > > numrecs = 0
> > > End If
> > > End With
> > >
> > > 'count records in qryAllOpenItems
> > > Set rst2 = db.OpenRecordset("SELECT [Exception Tracking].*, [Loan
> > > Tracking].[LT DB Database], [Loan Tracking].[LT Internal Number] FROM
> > > [Loan Tracking] INNER JOIN [Exception Tracking] ON [Loan Tracking].[LT
> > > Loan Shortname] = [Exception Tracking].[ET LN Shortname] WHERE
> > > ((((((Not [ET Closed]=-1))) AND ((Not [ET Amount]=0))) AND ((Not [ET
> > > Erroneous Entry]=-1))))")
> > > With rst2
> > > If rst2.EOF = False Then
> > > rst2.MoveLast
> > > numrecs2 = rst2.RecordCount
> > > Debug.Print numrecs2 '(74 records)
> > > Else
> > > numrecs2 = 0
> > > End If
> > > End With
> > >
> > > prelimpercent = numrecs / numrecs2 '19/74
> > > percent = prelimpercent * 100
> > > Debug.Print percent[/color][/color]
>
> MGFoster <me@privacy.com> wrote in message news:<hjxhd.1178$O11.749@newsread3.news.pas.earthl ink.net>...[color=green]
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Don't know if this is the solution, just saw it right-off:
> >
> > Change this:
> >
> > Dim rst, rst2 As DAO.Recordset
> > Dim db As DAO.Database
> > Dim numrecs, numrecs2 As Integer
> > Dim percent, prelimpercent As Integer
> >
> > to this:
> >
> > Dim rst as DAO.Recordset, rst2 As DAO.Recordset
> > Dim db As DAO.Database
> > Dim numrecs As Integer, numrecs2 As Integer
> > Dim percent As Integer, prelimpercent As Integer
> >
> > Variables dimmed w/o their data type default to Variants.
> >
> > --
> > MGFoster:::mgf00 <at> earthlink <decimal-point> net
> > Oakland, CA (USA)
> >
> > -----BEGIN PGP SIGNATURE-----
> > Version: PGP for Personal Privacy 5.0
> > Charset: noconv
> >
> > iQA/AwUBQYahTYechKqOuFEgEQLD1QCfegG1dIdt0cioN5RuSKoWN9 yaEOcAoLZX
> > eYnPuUemIPGtXfXcSp6Xg4TJ
> > =Dukc
> > -----END PGP SIGNATURE-----
> >
> >[/color]
>
> What you didn't spot is that he's storing his prelimpercent (a number
> between 0 and 1) into an INTEGER - which can only be 0 or 1, and so
> the result will always be either 0% or 100%, after the multiplication.
>
> Option 1) Store the prelimpercent into a Double,
>
> Option 2) Multiply numrecs by 100 BEFORE doing the division.
>
> Either will work, whatever floats your boat really (although,
> obviously, if you want fractional percentages, option 1 is the way to
> go).
>
> Damien[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.