Openning connection.....
Dim App_Cnn As ADODB.Connection
Set App_Cnn = New ADODB.Connection
With App_Cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = App_Folder & App_Dbase
'For user level security uncomment the following lines
' .Properties("Jet OLEDB:System database") = App_Folder & Sys_Dbase
' .Properties("User ID") = PowerUser
' .Properties("Password") = PowerPassword
' .Properties("Persist Security Info") = False
.Properties("Mode") = adModeReadWrite
.Properties("Jet OLEDB:Engine Type") = 5
.Properties("Locale Identifier") = 1033
.Open
End With
Closing & cleanning
App_Cnn.Close
Set App_Cnn = Nothing
------------------------------------------------------
Linking Procedure
Sub ImportSchema(Pinakas As String)
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
'Linking new file to DB
Set cat.ActiveConnection = App_Cnn
Set tbl.ParentCatalog = cat
With tbl
.Properties("Jet OLEDB:Create Link") = True
.Properties("Jet OLEDB:Link Provider String") = "Text"
.Properties("Jet OLEDB:Link Datasource") = Data_Folder
.Properties("Jet OLEDB:Remote Table Name") = Pinakas & ".txt"
.Name = "N_" & Pinakas
End With
cat.Tables.Append tbl
cat.Tables.Refresh
'Clearing old records of the table
App_Cnn.Execute "Delete " & Pinakas & ".* From " & Pinakas & ";", adExecuteNoRecords, adCmdText
'Insterting new records
App_Cnn.Execute "Insert into " & Pinakas & " Select N_" & Pinakas & ".* From N_" & Pinakas & ";", adExecuteNoRecords, adCmdText
'Unlinking file
cat.Tables.Delete "N_" & Pinakas
'Clear objects
Set tbl = Nothing
Set cat = Nothing
End Sub
------------------------------------------------------
Rest code
For any recordsets use
rst.ActiveConnection=App_Cnn
For bulk transactions use
App_Cnn.Execute sqlCode, adExecuteNoRecords, adCmdText
------------------------------------------------------
Explaination of variables:
App_Folder ---> Folder of This database, .mdw, 2nd database
App_Dbase ---> The name of This database
Sys_Dbase ---> The name of .mdw file
PowerUser ---> A user for read/write/delete/update etc
PowerPassword --->His password
Pinakas ---> The table name to import new records (olds are deleted)
Data_Folder --> Folder of Schema.ini file and new file to import
Schema.ini ---> File containing record layout of the importing file
Looks like
------------------------------------------------------
[Ecl1.txt] -----> Filename to be imported, Ecl1
is also a table name in the 2nd database
ColNameHeader = False
Format = Delimited(|)
MaxScanRows=0
CharacterSet = ANSI
DateTimeFormat=yyyy-mm-dd
DecimalSymbol=,
TextDelimiter=None
NumberLeadingZeros=True
Col1=Product Integer
Col2=Subproduct Integer
Col3=Status Char Width 1
Col4=Status_Discript Char Width 255
Col5=BusUnit Integer
Col6=Bank Integer
Col7=Center Integer
Col8=Main Double
Col9=Chkdgt Integer
Col10=Last_Status_Date Date
.
.
.
[Sbc1.txt] ---> Like Ecl1.txt but of different structure
ColNameHeader = False
CharacterSet = OEM
Format = FixedLength
FixedFormat=TrueFixedLength
DateTimeFormat=yyyymmdd
TextDelimiter=None
Col1=Branch Integer Width 3
Col2=Cncy Integer Width 4
Col3=Account Double Width 13
Col4=FirstName Char Width 20
Col5=LastName Char Width 40
Col6=Valid DateTime Width 8
.
.
.
------------------------------------------------------
In order to write your schema.ini file use notepad.