how to code to transfe data from excel worksheet to ms access database
how to code to transfe data from excel worksheet to ms access database
(OP)
Hi guys,
I want to transfer the data from a column in excel into ms access database. I need help.
thanks in advance
regards
I want to transfer the data from a column in excel into ms access database. I need help.
thanks in advance
regards
RE: how to code to transfe data from excel worksheet to ms access database
http://lessthandot.com
RE: how to code to transfe data from excel worksheet to ms access database
thanks.
RE: how to code to transfe data from excel worksheet to ms access database
Well, first we may need more specific info...
Are you writing this in VBA, or in VB6, or where?
RE: how to code to transfe data from excel worksheet to ms access database
RE: how to code to transfe data from excel worksheet to ms access database
In the code window type the word:
IN
put the cursor on it and hit F1.
Select "VB"
then select "IN clause"
then select "Example"
further down you see an example for Excel.
To append data to an existing table use something like:
CODE
Public Sub Excel1()
Dim dbcon As adodb.Connection
Dim sXlsPath As String
sXlsPath = "C:\MyExcelTable.xls"
Set dbcon = New adodb.Connection
With dbcon
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Properties("Data Source") = "C:\MyDatabase.MDB"
.Open
End With
'"myTable" is the table in the Mdb
'"Field1" is a field in "myTable"
'"A" is the xls column name
'"Worksheet1$" is the name of the Worksheet
dbcon.Execute _
"INSERT INTO myTable(Field1) " & _
"SELECT [A] AS Field1 " & _
"From [Worksheet1$] " & _
"IN '" & sXlsPath & "' 'EXCEL 8.0;'"
'To append data from all columns, and all columns are in myTable with the same names, then you can shorten it as:
'dbcon.Execute _
"INSERT INTO myTable " & _
"SELECT * " & _
"From [Worksheet1$] " & _
"IN '" & sXlsPath & "' 'EXCEL 8.0;'"
End Sub
RE: how to code to transfe data from excel worksheet to ms access database
so may not work or may work and corrupt the information already in your table
MichaelRed
RE: how to code to transfe data from excel worksheet to ms access database
What is V&V ?
If there is a problem with corrupting data in the MS Access db table, then I would think that a recordset could be used instead, and then loop through the records, inspecting the values and then adding them one at a time to the table.
CODE
dim sCmdTxt as string
Set rs = adodb.recordset
set rs.ActiveConnection = dbcon
sCmdTxt = "SELECT * " & _
"From [Worksheet1$] " & _
"IN '" & sXlsPath & "' 'EXCEL 8.0;'"
"
rs.Open sCmdTxt
do until rs.Eof
'Add records to db table one at a time
loop
RE: how to code to transfe data from excel worksheet to ms access database
and there are numerous approaches to the solution
doing the process on a record by record then field by field basis has, for me, proven painfully slow.
the process I outlined is essentially an attempt to bulk process the imports one feature at a time.
or (verification / validation of 'batches' of information)
MichaelRed
RE: how to code to transfe data from excel worksheet to ms access database
Best
RE: how to code to transfe data from excel worksheet to ms access database
A good way to thank Tek-Tips people who have helped you is to click the link shown on each post, it looks like this:
Thank MichaelRed
for this valuable post!
or
Thank SBerthold
for this valuable post!
http://lessthandot.com