Solved

Getting count results froma query

Posted on 2004-10-08
14
485 Views
Last Modified: 2010-08-05
I have a query which is called CountIP

SELECT count(*)
FROM attendance_tracking INNER JOIN attendance_code ON attendance_tracking.A_Code = attendance_code.A_Code
WHERE (((attendance_tracking.A_Code)="IP") AND ((attendance_tracking.PersonID)=CurrentUser()));


which obviously returns a value as an integer

However in my VBA code i try the following



Private Sub Report_Open(Cancel As Integer)
Dim IP, IPH, JD, NA, NAh, PB, PO, ULA, V, VH As Integer
IP = [CountIP]![Expr1000]
MsgBox "hello"
End Sub

however the report does not load or even atempt to load because it doe not like the code i have used, can anyone tell me the problem


Thanks
0
Comment
Question by:jon6
  • 7
  • 6
14 Comments
 
LVL 5

Expert Comment

by:ZenMasterrr
ID: 12256820
maybe its Expr1000....... try

...... SELECT count(*) as CountOfIP....

IP = [CountIP]![CountOfIP]


Zen :))
0
 
LVL 1

Author Comment

by:jon6
ID: 12256838
Sorry that does not work either
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12256868
Try this:

Private Sub Report_Open(Cancel As Integer)
    Dim IP, IPH, JD, NA, NAh, PB, PO, ULA, V, VH As Integer
    Dim cnn As Object
    Dim rst As Object

    Set cnn = CreateObject("ADODB.Connection")
    Set rst = CreateObject("ADODB.Recordset")
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    rst.Open "SELECT * FROM CountIP", cnn

    IP = rst!Expr1000
    MsgBox "hello"

End Sub
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12256872
Sorry... forgot the cleanup

Private Sub Report_Open(Cancel As Integer)
    Dim IP, IPH, JD, NA, NAh, PB, PO, ULA, V, VH As Integer
    Dim cnn As Object
    Dim rst As Object

    Set cnn = CreateObject("ADODB.Connection")
    Set rst = CreateObject("ADODB.Recordset")
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    rst.Open "SELECT * FROM CountIP", cnn

    IP = rst!Expr1000

    rst.close
    Set cnn = Nothing
    Set rst = Nothing
    MsgBox "hello"

End Sub
0
 
LVL 1

Author Comment

by:jon6
ID: 12256892
It says user defined type not recognised regarding

Set rst = New ADODB.Recordset


I tried changing it to this because it did not work, but niether does this

 Dim IP, IPH, JD, NA, NAh, PB, PO, ULA, V, VH As Integer
    Dim cnn As Object
    Dim rst As Object

    Set cnn = CreateObject("ADODB.Connection")
    Set rst = CreateObject("ADODB.Recordset")
    Set cnn = CurrentProject.Connection
    Set rst = New ADODB.Recordset

    rst.Open "SELECT Count(*) AS CountOfIP FROM attendance_tracking INNER JOIN attendance_code ON attendance_tracking.A_Code = attendance_code.A_Code WHERE (((attendance_tracking.A_Code)='IP') AND ((attendance_tracking.PersonID)=CurrentUser()))", cnn

    IP = rst!CountOfIP
    MsgBox "hello"

Thanks for your help and please keep it coming
0
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 150 total points
ID: 12256949
Sorry, that line is un-needed. Try this:


    Dim IP, IPH, JD, NA, NAh, PB, PO, ULA, V, VH As Integer
    Dim cnn As Object
    Dim rst As Object

    Set cnn = CreateObject("ADODB.Connection")
    Set rst = CreateObject("ADODB.Recordset")
    Set cnn = CurrentProject.Connection

    rst.Open "SELECT Count(*) AS CountOfIP FROM attendance_tracking INNER JOIN attendance_code ON attendance_tracking.A_Code = attendance_code.A_Code WHERE (((attendance_tracking.A_Code)='IP') AND ((attendance_tracking.PersonID)=CurrentUser()))", cnn

    IP = rst!CountOfIP
    MsgBox "hello"
0
 
LVL 1

Author Comment

by:jon6
ID: 12256959
That works thanks
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12256973
Glad to help! ThanX for the points!

God bless!

Sam

PS. Don't forget the cleanup part after the msgbox:

    rst.close
    Set cnn = Nothing
    Set rst = Nothing
0
 
LVL 1

Author Comment

by:jon6
ID: 12256986
Thanks you

God BLess you too
0
 
LVL 1

Author Comment

by:jon6
ID: 12257032
One last thing, i have a label on the form called Label12 how can i put the information into that label

Thanks
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12257045
I think this should work:

Me!Label12 = IP

insert it right after the "IP = rst!CountOfIP" line
0
 
LVL 1

Author Comment

by:jon6
ID: 12257084
For some reason it does not work. I have tried putting the name of the report and then the name of the label and still it does not work
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12257151
Sorry I think that should be:

Me!Label12.Caption = IP
0
 
LVL 1

Author Comment

by:jon6
ID: 12257208
THanks that work

Cheer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now