Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 20th, 2006, 03:57 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wont Give me a Percent

Throughout my pogram I am adding up numbers in the lngPercentFit var and then I divide it by lngTotalTtl( I just set it to 5 for this example) The problem is that all I can ever get it to return to the field is 0.00% or like 100.00% or 300.00%. If it dosent divide evenly I get 0%. I have also tried double as a datatype with the same results. Any light you can shed would be greatly appreciated.

    Dim lngPercentFit As Single
    Dim lngTotalTtl As Single

    lngPercentFit = 5
    lngTotalTtl = rstTotalTbl![LS_Fit_Weld_Visual] + rstTotalTbl![GW_Fit_Weld_Visual] + rstTotalTbl![RW_Fit_Weld_Visual] + rstTotalTbl![FW_Fit_Weld_Visual]

    rstResultTbl.Edit
    rstResultTbl![% Completed] = lngPercentFit / lngTotalTtl
    rstResultTbl.Update
    rstResultTbl.MoveNext
 
Old September 21st, 2006, 11:01 AM
pjm pjm is offline
Authorized User
 
Join Date: Jul 2006
Posts: 70
Thanks: 0
Thanked 0 Times in 0 Posts
Default

A solution doesn't jump out at me. While the 2 variables in the code are declared as Single, I can't tell if you have the table field defined as Single (or Double).

The slightly confusing thing about your code is that the prefix "lng" is usually used (in my experience) to mean Long Integer. Obviously this will not effect your result but it is confusing none-the-less.

-Phil-
 
Old September 21st, 2006, 12:24 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, I figured it out. It was as you mentioned, I didnt have the fields in my table declared as Single. I also changed the lng to sgl :P Thanks for the input

JR





Similar Threads
Thread Thread Starter Forum Replies Last Post
Top percent Query acting strangely in access 2002 jeremy1048 Access 4 January 15th, 2008 09:27 AM
how to add 6 percent to a number? keyvanjan Classic ASP Basics 2 October 10th, 2007 11:31 AM
JetComp Wont Work .....HELP!! timmaher Access VBA 3 August 25th, 2005 01:38 AM
percent of subtotal mtlpp Excel VBA 0 May 14th, 2005 10:09 AM
Can't Get Percent Format to Work Properly twsinc Access VBA 2 November 19th, 2004 09:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.