473,396 Members | 1,924 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.

Show record count from a SQL Server Temp Table used in a form recordsource

I am using a stored procedure as the recordsource on an MS-Access2000
form:
Forms!frmName.RecordSource = "dbo.myStoredProcedure"

The stored procedure creates a temp table #Contacts and then inserts
matching KeyID values contacts into it. Then I use a union query in
the same stored procedure to create the actual recordset.

What I want to know is how I can return the number of records in the
temp table #Contacts back to MS Access and display it?

I can't just do a VBA recordcount because that will count all the
records returned from the union queries.

What I am doing now feels sloppy, which is to count the records in the
temp table, then display the count (@myCount) in every row of the
recordset, which I display in the header of the form.

Any help is appreciated,
LQ

Example below:

Alter Procedure "myStoredProcedure"
AS
set nocount on

DECLARE @myCount as integer

CREATE TABLE #Contacts (id int identity, ContactID int)

INSERT INTO #Contacts(ContactID)
SELECT
Contacts.ID
FROM
Contacts
WHERE
Contacts.LastName = 'Jones')
SELECT @myCount = count(*) FROM #Contacts

SELECT
#Contacts.ContactID,
NULL as DATA,
@myCount AS CNT
FROM
#Contacts

UNION SELECT
#Contacts.ContactID,
Addresses.AddressInfo AS DATA,
@myCount AS CNT

FROM
#Contacts LEFT OUTER JOIN
Addresses ON
#Contacts.ContactID = Addresses.ContactID
Nov 13 '05 #1
2 15417
"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47**************************@posting.google.c om...
I am using a stored procedure as the recordsource on an MS-Access2000
form:
Forms!frmName.RecordSource = "dbo.myStoredProcedure"

The stored procedure creates a temp table #Contacts and then inserts
matching KeyID values contacts into it. Then I use a union query in
the same stored procedure to create the actual recordset.

What I want to know is how I can return the number of records in the
temp table #Contacts back to MS Access and display it?


Return the value as an output parameter. Instead of binding the form
directly to the procedure, (I guess this is an ADP?), create the recordset
in code with ADO - then you can read the returned parameter and bind the
recordset to the form.
Nov 13 '05 #2
Laren,
=Count(*) in a text control on the form will count the rows in the form.
Doesn't matter what the source of the data is. Also, you can add an aliased
value ("CONTACTS" AS SELECT_SOURCE . . .) to your union query that
identifies which select statement contributed the result. You can then use
DCount to count only those from the select statement that has your contacts.

"Lauren Quantrell" <la*************@hotmail.com> wrote in message
news:47**************************@posting.google.c om...

What I want to know is how I can return the number of records in the
temp table #Contacts back to MS Access and display it?

Nov 13 '05 #3

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

Similar topics

3
by: Don Seckler | last post by:
I have a data entry form called Draw. This form is used to enter data in the table called Draw. The table has the following fields: WholesalerID, MagID, IssueID, CopiesDist, and the index is...
1
by: Ryan | last post by:
I've got a problem I have't run up against before. I generally test for an empty recordset using BOF and EOF. Today, for the first time I ran into a problem where my recordset shows BOF and EOF =...
13
by: ricky.agrawal | last post by:
I'm really not sure how to go about this in Access. What I've created is a table for each location. Those tables are identical in format but different in information. The tables are named after...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
2
by: Catch_22 | last post by:
Hi, I have a stored procedure that has to extract the child records for particular parent records. The issue is that in some cases I do not want to extract all the child records only a...
2
by: Swinky | last post by:
I hope someone can help...I feel like I'm walking in the dark without a flashlight (I'm NOT a programmer but have been called to task to do some work in Access that is above my head). I have...
7
by: john | last post by:
In my form I have a master table and a details table linked 1xM. I can search through the whole parent table but I also like to be able to search through the child table fields to find parent...
3
by: Phil Stanton | last post by:
I have a form based on a complex query (Lots of tables) If I delete a record, everything appears to be OK. Get the message "Youa are about to delete 1 record ....". I say yes. The record count...
12
by: tekctrl | last post by:
Environment; Win2K PC with 1Gb of RAM and plenty of HD space running Access 2002 Issue; Access presents a blank data entry form in the Forms view when the New Record icon is used. However, it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
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.