LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Check for Primary Key

Here a QA program that I have in Excel. the user clicks a button then this
program loops through all the mdb files in a folder on our network. Each
database has the same 12 tables but the databases all have different names.
The program does a query on each table---just a simple record cound and then
prints the database name, table name and record cound in the spreadsheet. it
works really well and has reduced a 6 hour job to about 20 minutes. there's
just one more thing I need to add. I need to check each table for a primary
key. If there is one I would like to add it to this line as a variable.

ActiveCell.FormulaR1C1 = DBName & ";" & table & ";" & _
rs.Fields("Count").Value

thanks,


Sub CommandButton1_Click()
Dim rs As Recordset
Dim SQlcmd As String
Dim myTables As Variant
Dim table As Variant
Dim DBName As String
Dim rows As Integer

Call testfile

On Error Resume Next

Set LastCellInA = Sheet3.Range("A:A").SpecialCells(xlCellTypeLastCel l)
UsedRowsInA = LastCellInA.Row



myTables = Array("[FDMS Billing Fees]", _
"[FDMS Card Entitlements]", _
"[FDMS Card Specific Amex]", _
"[FDMS FEE History]", _
"[FDMS financial history]", _
"[FDMS financial history 2]", _
"[FDMS Link New Xref]", _
"[FDMS Merchant ABA/DDA New]", _
"[FDMS Merchant Funding Category DDAs]", _
"[FDMS Merchant Control Data]", _
"[tblFDMSInternationalGeneral]", _
"[tbl_FDMS_PhaseII_Additional_info]")



'DBName = ListBankNames.Value


For rows = 1 To UsedRowsInA

DBName = Sheet3.Cells(rows, 1)


For Each table In myTables

SQlcmd = "Select Count(*) as [Count] From " & table

Set rs = New ADODB.Recordset

rs.Open Source:=SQlcmd, _
ActiveConnection:="Provider=Microsoft.Jet.OLEDB.4. 0; Data Source=N:\Data
Warehouse\Dallas\MASSCD\AccessDatabases\" + _
DBName + "; User Id=admin; Password="

Range("A65000").End(xlUp).Offset(1, 0).Activate




ActiveCell.FormulaR1C1 = DBName & ";" & table & ";" & _
rs.Fields("Count").Value

Next table

Next rows

Application.DisplayAlerts = False

Call TextToColumns

Application.DisplayAlerts = True
End Sub


Public Sub testfile()
Dim fso, fo, fl, f
Dim r
r = 1
Set fso = CreateObject("Scripting.filesystemobject")
Set fo = fso.getfolder("N:\Data Warehouse\Dallas\MASSCD\AccessDatabases\")
Set fl = fo.Files
For Each f In fl
If Right(f.Name, 3) = "mdb" Then
Sheet3.Cells(r, 1) = f.Name
r = r + 1
End If
Next
End Sub
--
Billy Rogers

Dallas,TX

Currently Using Office 2000
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating a primary key Access::Student Excel Discussion (Misc queries) 7 July 1st 09 11:07 PM
(Primary) Key Column? Rebecca Excel Discussion (Misc queries) 5 September 21st 08 05:14 PM
Combining data using a primary key Jamieson Bourque Excel Discussion (Misc queries) 1 December 13th 06 07:33 PM
Primary & Secondary axes to have same value Julie Charts and Charting in Excel 1 December 4th 06 09:05 AM
primary & secondary axis Connie Martin Charts and Charting in Excel 3 March 8th 06 03:01 PM


All times are GMT +1. The time now is 01:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"