count of records in a table in external database

Hi,

I would like to get the record count of a table in an external database 
(using the name of the table in the loop of the current database).

What I've tried (doesn't work):

SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" & 
rs!Name & "]")



The procedure (**** is where the problem line is):

------------------------------

Public Sub AppendTableRecords()

Dim strSelectAllTables As String

strSelectAllTables = "SELECT NAME FROM MSysObjects WHERE Type=1 AND Name not 
like 'MSys%';"

Dim rs As New ADODB.Recordset
rs.Open strSelectAllTables, CurrentProject.Connection, _
adOpenKeyset, adLockOptimistic

DoCmd.SetWarnings False

While Not rs.EOF


DestinationDbCount = DCount("*", rs!Name)

'****
SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" & 
rs!Name & "]")
'****

CountDifference = SourceDbCount - DestinationDbCount


rs.MoveNext
Wend
DoCmd.SetWarnings True

rs.Close

Set rs = Nothing

Close #iFileNo

End Sub

---------------------------

How can I get the record count of a table in an external db using 'rs!Name' 
as the external database's table name?

-Ben
0
Utf
11/27/2009 4:53:02 PM
access.modulesdaovba 1670 articles. 0 followers. Follow

2 Replies
1280 Views

Similar Articles

[PageSpeed] 0

"Ben8765" <Ben8765@discussions.microsoft.com> wrote in message 
news:9688EA08-8BED-45B3-816F-5FD242BA7809@microsoft.com...
> Hi,
>
> I would like to get the record count of a table in an external database
> (using the name of the table in the loop of the current database).
>
> What I've tried (doesn't work):
>
> SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" &
> rs!Name & "]")
>
>
>
> The procedure (**** is where the problem line is):
>
> ------------------------------
>
> Public Sub AppendTableRecords()
>
> Dim strSelectAllTables As String
>
> strSelectAllTables = "SELECT NAME FROM MSysObjects WHERE Type=1 AND Name 
> not
> like 'MSys%';"
>
> Dim rs As New ADODB.Recordset
> rs.Open strSelectAllTables, CurrentProject.Connection, _
> adOpenKeyset, adLockOptimistic
>
> DoCmd.SetWarnings False
>
> While Not rs.EOF
>
>
> DestinationDbCount = DCount("*", rs!Name)
>
> '****
> SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" &
> rs!Name & "]")
> '****
>
> CountDifference = SourceDbCount - DestinationDbCount
>
>
> rs.MoveNext
> Wend
> DoCmd.SetWarnings True
>
> rs.Close
>
> Set rs = Nothing
>
> Close #iFileNo
>
> End Sub
>
> ---------------------------
>
> How can I get the record count of a table in an external db using 
> 'rs!Name'
> as the external database's table name?



    Dim dbExt As DAO.Database

    Set dbExt = DBEngine.OpenDatabase( _
        "GOOD_DATA_SAR_Recovery_Tracking_db.mdb")

    ' ...

        SourceDbCount = dbExt.TableDefs(rs!Name).RecordCount

    ' ...

    dbExt.Close

If you're doing this in a loop, you're goiing to want to open the external 
database outside the loop, so as not to repeat that overhead in every 
iteration.

I believe that the RecordCount property should be accurate for a TableDef. 
If it isn't, you would have to open a recordset from dbExt on a SELECT 
Count(*) query, and get the count from the recordset.

-- 
Dirk Goldgar, MS Access MVP
Access tips: www.datagnostics.com/tips.html

(please reply to the newsgroup)

0
Dirk
11/27/2009 7:09:32 PM
Thanks a lot for your reply. I will try this tomorrow.

-ben

"Dirk Goldgar" wrote:

> "Ben8765" <Ben8765@discussions.microsoft.com> wrote in message 
> news:9688EA08-8BED-45B3-816F-5FD242BA7809@microsoft.com...
> > Hi,
> >
> > I would like to get the record count of a table in an external database
> > (using the name of the table in the loop of the current database).
> >
> > What I've tried (doesn't work):
> >
> > SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" &
> > rs!Name & "]")
> >
> >
> >
> > The procedure (**** is where the problem line is):
> >
> > ------------------------------
> >
> > Public Sub AppendTableRecords()
> >
> > Dim strSelectAllTables As String
> >
> > strSelectAllTables = "SELECT NAME FROM MSysObjects WHERE Type=1 AND Name 
> > not
> > like 'MSys%';"
> >
> > Dim rs As New ADODB.Recordset
> > rs.Open strSelectAllTables, CurrentProject.Connection, _
> > adOpenKeyset, adLockOptimistic
> >
> > DoCmd.SetWarnings False
> >
> > While Not rs.EOF
> >
> >
> > DestinationDbCount = DCount("*", rs!Name)
> >
> > '****
> > SourceDbCount = DCount("*", "[GOOD_DATA_SAR_Recovery_Tracking_db.mdb].[" &
> > rs!Name & "]")
> > '****
> >
> > CountDifference = SourceDbCount - DestinationDbCount
> >
> >
> > rs.MoveNext
> > Wend
> > DoCmd.SetWarnings True
> >
> > rs.Close
> >
> > Set rs = Nothing
> >
> > Close #iFileNo
> >
> > End Sub
> >
> > ---------------------------
> >
> > How can I get the record count of a table in an external db using 
> > 'rs!Name'
> > as the external database's table name?
> 
> 
> 
>     Dim dbExt As DAO.Database
> 
>     Set dbExt = DBEngine.OpenDatabase( _
>         "GOOD_DATA_SAR_Recovery_Tracking_db.mdb")
> 
>     ' ...
> 
>         SourceDbCount = dbExt.TableDefs(rs!Name).RecordCount
> 
>     ' ...
> 
>     dbExt.Close
> 
> If you're doing this in a loop, you're goiing to want to open the external 
> database outside the loop, so as not to repeat that overhead in every 
> iteration.
> 
> I believe that the RecordCount property should be accurate for a TableDef. 
> If it isn't, you would have to open a recordset from dbExt on a SELECT 
> Count(*) query, and get the count from the recordset.
> 
> -- 
> Dirk Goldgar, MS Access MVP
> Access tips: www.datagnostics.com/tips.html
> 
> (please reply to the newsgroup)
> 
0
Utf
11/27/2009 9:04:06 PM
Reply:

Similar Artilces:

Problems Moving Database Files
Hi there, yesterday if been trying to perform a pretty usual task: Moving Exchange 2003 Databases (priv+pub edb+stm) files from one HardDisk (with Letter E:) to another HardDisk (with Letter D:) using the SystemManager. Everything worked fine, SystemManager moved the DBs without any Probs. But after a restart of the server (and removing the Harddisk for Drive E) , the store wouldn't start: "I/O Error: Cant find file E:\..." (similar quote) The Store was still looking in the old place... So I changed the drive Letter of Drive D from D to E...and the store mounted without any ...

Pivot table and counting.
I have a pivot table that gives me the number of rides done by a van. I can have the pivot table return the number of rides, but what I need is the number vans that participated for a certain day. Example, it is possible to have 27 trips done by 18 vans, how can I count the number of vans and not addup the van number? Any help appreciated. Thank you, Joe Hi Joe We need a bit more information on how your source data table is set up. What information do you have in each column? -- Regards Roger Govier sacredarms <sacredarms@discussions.microsoft.com> wrote: > I have a pi...

Invalid Pivot Table Message
I created a cube (under Analysis Server Windows 2000) with some date fields and processed it. Everthing went fine. I then created an Excel (XP) spread sheet and did 'Import External Data' / 'New database query' / 'OLAY Cubes' / to my cube. I saved the spreadsheet and sent it to my co-worker. When he opened the spreadsheet on his PC it opened fine; but when he double clicked on a year column to expand, he got a message 'Invalid Pivot table'. What am I doing wrong? Thanks, S.Kumar P.S. I posted a similar message in the sqlserver.olap forum but there was no ...

Store Operations POS Item Table Field Suggestion
We would like to suggest adding a new "numeric" type field in the "Item" table of Store Operations. All of the customers that we have dealt with have only used numeric values in the "ItemLookupCode" field, however this field is an alphanumeric string, and does not offer true numeric sorting in applicable browsers. Not to alienate those clients that use alphanumeric characters in the ItemLookupCode field, we suggest adding several true numeric fields for custom data, then the user could sort on their numeric data. In addition to our encounters with numeri...

Cycle Counting
Hello, I am looking for ideas on how to cycle count serial number tracked items without increasing workload. Our serialized items are barcoded but the problem is the are situated on the pallet incorrectly and the pallet is placed on a third level of a racking system. If we could just cycle count based on item count and not include the serial number it would make it easy. Is this possible in Great Plains. We are running Great Plains 8.0. Any suggestions are greatly aprreciated. Thank You, Brian Morris Database Administrator ...

logon error accessing exchange mail externally
I have an SBS2K with E2K setup. E2K is hosting mail for 2 domains (@domaina.com and @domainb.com) on the same server. 2 users that have email addresses from both domains are unable to access their email from an external outlook connection, the others who just have one email have no problem logging on. I have tried telnet and the usual OE O2K configs with the same results. All users have been setup with the copy feature - therefore except for the name/email address the groups/permissions are the same. The above may not be the reason for the error but it is the only disparity between...

Lookup table with click-and-select?
Can someone point me in the right direction? I have several thermos bottles of various sizes that I use for tea. I have several varieties of tea that require different brewing parameters. I'd like to create a worksheet that will generate "brew slips" -- little slips of paper that show how much tea to use for each thermos. The left side of the sheet will be the brew sheet. It will have columns for ounces, cups, milliliters, grams of tea, etc. Something like this: Thermos Cups Oz mL g/pot A 2.0 16 473 ?? B 3.0 24 710 ?? C...

Count
Hi, I would like to know how which formula I should use to count some codes & to ignore the duplicated codes, for example in column A: Code 1234 4321 4321 1234 1234 3214 Now, I want Excel to count & the result is 3 which are: 1234-4321-3214 Yes I can use PivotTable, but I would like to use a formula because I have to deal with this every day. I appreciate your support. -- MFS22 COUNTIF will do it. =COUNTIF(Rng,Rng), where the criterion is the same as the range: e.g =COUNTIF(A3:A8,A3:A8) HTH Peter "MFS" wrote: > Hi, > I wo...

How do I count the # of times a value reoccurs and plot it over ti
I wish to plot a number of errors made by each users and compare it over time. I have a column of user ID's and a column of dates. I want the chart to count the number of times each user ID appears and plot against it's corresponding date. However, each time I try to do this, the chart appears wrong. Any ideas? In article <9595B2A1-8282-4AB3-8511-A6776E108164@microsoft.com>, Stephen@discussions.microsoft.com says... > I wish to plot a number of errors made by each users and compare it over > time. I have a column of user ID's and a column of dates. I want t...

Looking for Macro to load data from Access table
I need to code a button to delete data in a spreadsheet then reload the data from an Access table. I'm a new excel user so I down know where to start. Thanks Maybe this will help http://www.rondebruin.nl/accessexcel.htm -- Regards Ron de Bruin http://www.rondebruin.nl "Randy K" <wawork@hotmail.com> wrote in message news:43ff7bea.3595531@msnews.microsoft.com... >I need to code a button to delete data in a spreadsheet then reload > the data from an Access table. I'm a new excel user so I down know > where to start. > > Thanks ...

Mathematical Calculations in a form linked back to a table
Hello I palnning on implementing calculation between two fields, and the result within another field. Suppose I have three fields called A B and C respectively. In the form I plan on Inputing a value for[A] and Inputing a value for [B]. Now, Field [C] will calculate [A]-[B]. When filed [C] is calculated, it is not in the table, like A and B are. I would like to know how to solve this problem. It is rarely necessary to store a calculated value in a table in Access. Much more commonly, a form (as you are using) or a query is used to do the calculation "on the fly", as it were. ...

Line count
I am working with a program called Dictaphone. We use Word 2007 in this program. The line count on Dictaphone and the line count in Word 2007 are different even though the Dictaphone text is retrieved from Word 2007. Why would they be different? What is the difference between virutal line count and physical line count? ...

Resources
I understand there is a feature in Great Plains where I can pull up any screen in eEnterprise and see what column and table that text box is linked to? Is this true? What are the steps to get this information? ...

count number of characters in rich edit control
How can i count number of characters in rich edit control 2 If u mean controls of type Rich TextBox control, try RichControl1 RC1; CString Mes=RC.GetText(); int n=Mes.GetLength(); "Rahul" <Rahul@discussions.microsoft.com> wrote in message news:7743023C-EA83-4ACA-AB67-F1AE7279F1EB@microsoft.com... > How can i count number of characters in rich edit control 2 EM_GETTEXTLENGTHEX, WM_GETTEXTLENGTH, WM_GETTEXT, EM_STREAM* "Rahul" <Rahul@discussions.microsoft.com> wrote in message news:7743023C-EA83-4ACA-AB67-F1AE7279F1EB@microsoft.com... > How can i co...

External mail caching
We have two exchange 2003 servers running in Native mode. Currently there are no mailboxes on the 2nd server, it is used for testing purposes. We also have an external DNS MX record for each server. If the production server were to fail, would the second server receive external mail and cache it until the primary server is repaired then forward it? If not, does anyone have any suggestions to accomplish this? Thanks If they're part of same Exchange org than it will do that by default. If different Exchange organizations, you can configure an Exchange/smtp server to do it. -- Bh...

Counting sales
I have two different datasets. Each with a common identifier. I need a formula that will reference the identifiers in both datasets and count the number of sales a particular agent made. Example. look up this identifier in the other dataset and then give me the value that is 2 columns over from the identifier in the second dataset. See if this helps: http://contextures.com/xlFunctions02.html -- Biff Microsoft Excel MVP "Dave" <Dave@discussions.microsoft.com> wrote in message news:E7245B37-033F-400E-9CEE-9822BE7CB0F5@microsoft.com... >I have two...

Counting Cells with Conditional Formatting
Is there a way to look at a row of data that is either highlighted yellow or red and to count only the data that is highlighted yellow and give me that number? None of my data is numerical....just one letter data, i.e.: "S" or "U" I just want to count how many of the cells are highlighted yellow in a specific row, if that makes more sense. Here's a UDF (Put in a Standard module) and use it in cell A1, like =CountByColor(A8:H8,6) << where 6 (at present) = Yellow = change to =CountByColor(A8:H8,3) to get the reds HTH Function CountByColor(InRa...

COUNT ? need formula
Hi, I want to track the results of my teams sales performance. I record if it is a sale, no sale, cancelled etc in column M. I thought I'd be able to use the COUNT function/formula to be able to search for all the SALES in column M and place the result in a cell ( column O )but I can't work it out. Any ideas? Damian Hi! Try this: =COUNTIF(M1:M100,"sale") Biff "Diamond Jones" <kwanzaNOSPAM@optusnet.com.au> wrote in message news:43a0e897$0$17704$afc38c87@news.optusnet.com.au... > Hi, > > I want to track the results of my teams sales perf...

Count Function
I am creating a report for the number of pupils being collected at a certain collection time e.g. 14:00hr and 15:00hrs using the formula =Count([Child Last Name]) in the collection time footer However when i try to count the overall number of pupils in the footer using the same formula, 'Error' appears on screen? Thanks There are potentially a dozen footer sections in a report. Which one is giving you a problem? What is the name of the control? What is the exact formula? -- Duane Hookom Microsoft Access MVP "ELo" wrote: > I am creating a r...

Problem using FOXPRO Free Tables from Access 2000
I'm using Access 2000 linking FoxPro Tables via ODBC When I link tables with numeric fields Access gives me an error: "The Decimal field's precision is too small to accept the numeric you attempted to add." I find this problem in "Knowledge Base" I update my Windows XP to Jet 4.0 SP8 with Mdac 2.8 RMT and the last version of FoxPro ODBC Driver and but the problem is the same. Any help appreciated. ---------------------------------------------------------------------------- ---- ACC2000: Scaling Errors When You Query Linked Tables PSS ID Number: 270...

Counting a count
How do I count a count?? This is what im trying to do: I have a database with a table named tblMain and has incorporated everything within that table but contains info from about 8 other tables. I have not doesigned this database and it appears to have a very poor structure...anyway There are three fields involved in this process...'Request' (either 'dispensation', 'waiver' or 'dispensation and waiver'), 'Department' (which consists of 7 other drop down menu options) and 'RequestStatus' which contains the status of each request by another...

Update Kanji Char in SQL Database from Access returns question mar
I'm trying to update a SQL database from ms access. There is a a lot of Japanese data in kanji. I've imported the data into Access from Excel and it looks fine. When I do an update query in Access to the MS SQL db via ODBC, much of the data becomes question marks. All driver versions I could think of are listed below. This is all being done on a Japanese workstation to a Japanese server. Do I have to make any special configurations? Is there anything I can do? Thanks. Stuart Access version - 2000 9.0.2720 SQL Server 2000.85.1132.00 Running the following...

Powershell and log4net to SQL Database
Has anyone successfully used log4net to log to an SQL database? I am able to use log4net successfully when logging to console, files, eventlog, etc, however when attempting to log to the ADONetAppender, it cannot load my configuration file. Here are the Powershell commands used to get setup: $log4netDLL = "C:\Path\log4net.dll" $log4netConfig = "C:\Path\log4net.config" [Void][Reflection.Assembly]::LoadFile($log4netDLL) [Log4Net.LogManager]::ResetConfiguration() [Log4Net.Config.XmlConfigurator]::ConfigureAndWatch($log4netConfig) Here is the ADONetAppender section ...

Recording Administrative Fee on 401(k) in Money 2007
What is the appropriate way to record an administrative fee charged to shares on a 401(k) in Money 2007 - an "Other Expense" doesn't allow for a change in shares and faking out the software by entering a negative "Reinvested Capital Gaines" doesn't work either. Thanks, Phil D. I do a Sell to the Cash Account followed by an Expense (Miscellaneous:Service Charges & Fees or similar) in the Cash Account. I'm assuming you are not wanting to do the Sell. Why not? "Phil" <PhilipDeLaneyWV@gmail.com> wrote in message news:1168372938.333254.7351...

2002 Pivot Table Calculating Field
Can you place a calculated field in a Column next to an Excel List field? Example: Total Quater1 % Quarter2 % Quarter3 % Quarter4 % Sales Sales Sales Sales Sales 240 10 4 75 31 105 44 50 21 The % field is not in the Excel List. List example: Area Quarter Sales 1 2 50 2 3 75 3 2 25 4 1 10 5 4 35 6 ...