Solved

Getting count results froma query

Posted on 2004-10-08
14
507 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
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: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

763 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