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: 80
Default Adding table into existing access database via ADO

I have a following code that add customer ratings into our database. It will create a .mdb as per the customer number correspondes Range("PlayerId"). If the PlayerId is inuque, there is no problem with my code. However what I want is; if the DB file exists,to create another table as per value in Range("tblName"). Below is my code:
Thank you very much for your kind attention.
Baha

Code:
Option Explicit
Sub CreateDB_StaffReq()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim sDB_Path, sDB_PathBackUp As String
Dim cnn As ADODB.Connection
sDB_Path = "P:\Everyone\For Baha\RatingCalculator\" & "DB_" & Sheets("Data").Range("PlayerId").Value & ".mdb"

'On Error Resume Next
'FileCopy sDB_Path, sDB_PathBackUp
'Kill sDB_Path
'On Error GoTo 0

Set cat = New ADOX.Catalog
cat.Create _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & sDB_Path & ";"
Set tbl = New ADOX.Table
tbl.Name = "tbl" & Format(Range("tblName"), "hh:mm")
tbl.Columns.Append "GameId", adInteger
With tbl.Columns("GameId")
Set .ParentCatalog = cat
.Properties("AutoIncrement") = True
.Properties("Increment") = CLng(1)
End With
tbl.Columns.Append "Wagers", adVarWChar, 15
'-------------------------------------
cat.Tables.Append tbl
Call CreatePrKey_tblPlayerId(cat, "tbl" & Format(Range("tblName"), "hh:mm"), "GameId")
cat.ActiveConnection.Close
Set cat = Nothing
End Sub
Private Sub CreatePrKey_tblPlayerId(cat As ADOX.Catalog, strTableName As String, _
varPKColumn As Variant)
Dim tbl As ADOX.Table
Dim idx As ADOX.Index
Dim sDB_Path As String
Dim MyConn
Set tbl = cat.Tables(strTableName)
For Each idx In tbl.Indexes
If idx.PrimaryKey Then
tbl.Indexes.Delete idx.Name
End If
Next idx
Set idx = New ADOX.Index
With idx
.PrimaryKey = True
.Name = "PrimaryKey"
.Unique = True
End With
idx.Columns.Append varPKColumn
tbl.Indexes.Append idx
tbl.Indexes.Refresh
Set tbl = Nothing
Set idx = Nothing

End Sub
Sub PushTableToAccess_PlayerRating()
Dim cnn As ADODB.Connection
Dim MyConn
Dim rst As ADODB.Recordset
Dim i As Long, j As Long
Dim Rw As Long
Sheets("Data").Activate
Rw = Cells(65536, Range("ColNum").Value).End(xlUp).Row
Set cnn = New ADODB.Connection
MyConn = "P:\Everyone\For Baha\RatingCalculator\" & "DB_" & Sheets("Data").Range("PlayerId").Value & ".mdb"
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open MyConn
End With
Set rst = New ADODB.Recordset
rst.CursorLocation = adUseServer
rst.Open Source:="tbl" & Format(Range("tblName"), "hh:mm"), ActiveConnection:=cnn, _
CursorType:=adOpenDynamic, LockType:=adLockOptimistic, _
Options:=adCmdTable

For i = 3 To Rw
rst.AddNew
rst(1) = Cells(i, 1).Value
rst.Update
Next i
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
 
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
Adding hyperlink to access database from excel Mike Archer Excel Programming 1 February 1st 10 10:32 PM
HELP!: Popualte Access Database with data from 50 existing workboo sam Excel Programming 2 September 19th 09 01:58 AM
Transfer to an existing Access Table Secret Squirrel Excel Discussion (Misc queries) 0 March 17th 06 11:31 PM
Macro to Export Selected fields to an Existing Access Database ernie Excel Programming 1 March 13th 06 05:01 PM
adding formula to existing database Country Boy Excel Worksheet Functions 3 September 5th 05 03:50 PM


All times are GMT +1. The time now is 09:40 PM.

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"