Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access 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 November 23rd, 2006, 10:36 AM
Authorized User
 
Join Date: Nov 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default VB code in Report

I have a report with four fields; NAME,HIV,HBV,HCV,RPR. Apart from the NAME the others represent diseases. In this report each person represented by the NAME would tested for the four (4) disease markers. The result is indicated by either 1 which represents a negative result or 2 which represents a positive result. therefore, if an individual is negative in all the disease markers and another one is say positive for HIV, the report will appear like this;
NAME HIV HBV HCV RPR
Ben 1 1 1 1
Jane 2 2 1 1
Sila 1 2 2 1
etc
Now the task is to calculate the disease prevalence for each disease marker which has tested positive or has 2 indicated. the general formular is e.g for HIV the number of persons tested positive for HIV Divided by the total number of persons tested Multiplied by 100 to get percentage. according to our table one person tested positive to HIV out of the Three. therefore
HIV = 1/3 x 100 = 33%
HBV = 2/3 x 100 = 66%
HCV = 1/3 x 100 = 33%
RPR = 0 = 0%
The above calculations will show the disease prevalence and need to be displayed on the report .
How can I compute the above calculations using VBA Code in the report?

Bright Mulenga


Bmulenga
__________________
Bmulenga
 
Old November 23rd, 2006, 12:21 PM
Authorized User
 
Join Date: Nov 2006
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

in a vague answer to your question you can store all the data in a table, use a query to look it up, and use an if statement to see what calculation needs to be done (if any) and then store the result in a variable and stick all that data in a make table, that is the first macro the second macro opens a report bound to the make table, actually the first macro deletes all data in the make table, the second macro appends the make table, the third macro opens a report bound to the make table...

When I say make table what i mean is it is a table that you need to create manually with no relationship to any other table, its just sitting there for the purpose of solving your problem, you delete all data and append it every time you use it, i use them frequently for complex problem solving, there may be other ways of doing it but whatever works...

hope that helps
scott
 
Old November 27th, 2006, 08:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Hi,

   The proper way to store the positive and negative results would be with a check box and 0 for No and -1 for Yes. That being said, you have already indicated the method to find this answer.

   Create a report, then drop 4 text boxes (percentage format) on the report labeled with the test name, then on the report Detail section On Format event, put code like this, just change the name of the test:

Dim rs As ADODB.Recordset
Dim sSQL As String
Dim iCount As Integer
Dim iTotal As Integer
Dim lResult As Long

sSQL = "SELECT * FROM tblName" 'this is what I called the table.

Set rs = New ADODB.Recordset
rs.Open sSQL, CurrentProject.Connection

If rs.RecordCount <> 0 Then
rs.MoveFirst
    Do Until rs.EOF
    If rs("HIV") = "2" Then
        iCount = iCount + 1
    End If
    iTotal = iTotal + 1
    rs.MoveNext
    Loop
End If

rs.Close

lResult = (iCount / iTotal) * 100

Me.HIVText = lResult


HTH


mmcdonal
 
Old November 27th, 2006, 09:00 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

P.S. I used a text data type in my table since the numbers were not having any arithmetic calculations carried out against them. That is why iCount is looking for "2".

If you used a numeric data type in your table, then change the code to this:

If rs("HIV") = 2 Then



mmcdonal





Similar Threads
Thread Thread Starter Forum Replies Last Post
simple report and crystal report in vb.net saket123 .NET Framework 2.0 0 August 13th, 2008 06:55 AM
assign report permissions thru vb .net code polofson Reporting Services 0 April 15th, 2008 05:31 PM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05:44 AM
VB code in Report Modified bright_mulenga Access 1 November 24th, 2006 06:02 AM
Changing Crystal Report Title from VB Code Niaz Pro VB Databases 4 June 9th, 2004 09:51 PM





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