473,396 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Access 2002 - report record source on open event

I am trying to create a report that displays a name of an advertising
source and count of the number of times it was hit between certain date
ranges. The data is split between two different databases: this access
db, and a remote MySQL server. The MySQL tables are linked in the access db.

What I have done so far is created an On Open event for a report that
does the following:

* prompt user for the date range
* get which sources were hit during this period
* for each hit source in the time period...
* count times hit from this database
* count times hit from remote database through the linked tables

Inside the looping of each hit source, I set variables to hold the
source_name and the count of hits that source got. These are the pieces
of data that I want displayed in the report as a row.

Is there a way that I can create some kind of data structure to hold
each "row" which I can then set as the reports record source? Could
somebody give me a little direction on how to do what I am looking for?

Any help is *greatly* appreciated! TIA

Below is the On Open method to help with clarification:

Private Sub Report_Open(Cancel As Integer)
Dim rslt As ADODB.Recordset, rslt2 As ADODB.Recordset
Dim sqlstr As String
Dim sdate As String, edate As String
Dim source_name As String, source_id As String
Dim count As String, numSources As Integer

'prompt user for the date range
sdate = Format$(CDate(InputBox("Enter the Start Date")),
"General Date")
edate = Format$(CDate(InputBox("Enter the End Date")),
"General Date")

'get which sources were hit during this period
sqlstr = "SELECT DISTINCT (contacts.how_found) AS source_id, "
+"sources.name AS source_name FROM sources RIGHT"
+" JOIN contacts ON sources.id = contacts.how_found"
+" WHERE (((contacts.submitted) Between #" + sdate
+ "# And #" + edate + "#));"
Set rslt = New ADODB.Recordset
Set rslt.ActiveConnection = CurrentProject.Connection
rslt.Open (sqlstr)
numSources = 0
Do Until rslt.EOF
'for each hit source in the time period...
source_name = rslt.Fields("source_name").Value
source_id = rslt.Fields("source_id").Value
numSources = numSources + 1

'count times hit from this database
sqlstr = "SELECT Count(contacts.id) AS numReqs FROM contacts "
+"LEFT JOIN sources ON contacts.how_found = "
+"sources.id WHERE (((contacts.submitted) Between #"
+ sdate + "# And #" + edate
+ "#) AND ((sources.id)=" + source_id + "));"
Set rslt2 = New ADODB.Recordset
Set rslt2.ActiveConnection = CurrentProject.Connection
rslt2.Open (sqlstr)
count = rslt2.Fields("numReqs").Value
rslt2.Close

'count times hit from remote database through the linked tables
sqlstr = "SELECT Count(itcvb_contacts.id) AS numReqs FROM "
+"itcvb_contacts LEFT JOIN itcvb_sources ON "
+"itcvb_contacts.how_found = itcvb_sources.id WHERE "
+"(((itcvb_contacts.submitted) Between #" + sdate
+"# And #" + edate + "#) AND ((itcvb_sources.id)="
+ source_id + "));"
rslt2.Open (sqlstr)
count = count + rslt2.Fields("numReqs").Value
rslt2.Close

Set rslt2 = Nothing
rslt.MoveNext

'I now know the number of hits for this source
'need a way to make a row in the report to display the
' source_name and count
'can I create a data structure to use as the report's
' data Record Source ??

Loop
rslt.Close
Set rslt = Nothing
End Sub
--
Justin Koivisto - sp**@koivi.com
Nov 12 '05 #1
1 2699
Heh.. managed to work out a query for this (sometimes I feel really stupid):

SELECT
DISTINCT sources.name,
(
SELECT
COUNT(contacts.id)
FROM contacts
WHERE
contacts.how_found=sources.id
AND contacts.submitted Between $sdate And $edate
) + (
SELECT
COUNT(it_contacts.id)
FROM it_contacts
WHERE
it_contacts.how_found=sources.id
AND it_contacts.submitted Between $sdate And $edate
) AS hits,
$sdate AS sdate,
$edate AS edate
FROM sources
RIGHT JOIN contacts
ON sources.id = contacts.how_found
WHERE
contacts.submitted Between $sdate And $edate;

--
Justin Koivisto - sp**@koivi.com
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: rickcheney | last post by:
I just changed my Access 2002 database to a SQL Server ADP project. I had a form where the user entered a value into a text box and when a command button on the form was clicked a Report was...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
9
by: Colin McGuire | last post by:
Hi, I have an report in Microsoft Access and it displays everything in the table. One column called "DECISION" in the table has either 1,2, or 3 in it. On my report it displays 1, 2, or 3. I want...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
8
by: lauren quantrell | last post by:
When I open an Access form I can have no recordset specified, then in the form's OnOpen event I can do something like: Me.paramaters = "@SomeColumn = 22)" Me.recordsource = "dbo.sproc123" But I...
3
by: StBond | last post by:
Hi everyone, I am new to Access and Visual Basic so things my be getting across a bit cloudy. I only started using VB for one week. I am having a little problem with the database that I am...
7
by: manning_news | last post by:
I've got a report that's not sorting correctly. I build a SQL statement and assign it to the recordsource in the Open event, sorting the data the way the user chooses. The user can choose up to 3...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.