Solved

Getting count results froma query

Posted on 2004-10-08
14
475 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

760 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

21 Experts available now in Live!

Get 1:1 Help Now