Solved

Getting count results froma query

Posted on 2004-10-08
14
528 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
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
 
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

How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

630 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