PC Review


Reply
Thread Tools Rate Thread

Access command from Excel

 
 
JT
Guest
Posts: n/a
 
      19th Nov 2008
In my Excel macro, I am trying to import a spreadsheet into Access. I create
an Access object and am trying to use the "transfer spreadsheet" command. It
works but it is only importing the first line in the spreadsheet.

Below is the code I'm using:

AppAcc.DoCmd.TransferSpreadsheet acImport, 8, "Interest_Table",
"\\vs300\cost_center\ABC\UploadFile.xls", True

Any ideas or suggestions are greatly appreciated. Thanks for the help......
--
JT
 
Reply With Quote
 
 
 
 
Mike
Guest
Posts: n/a
 
      19th Nov 2008
try this way
Option Explicit
Private Sub saveDataToAccess()
'Needs reference the Axtive X Library 2.0 or higher
Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sSQL As String, strConn
Dim R As Integer
R = 6
'Use for Access (jet)
'Assumes that the access database is in the same folders as thisworkbook
strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
ThisWorkbook.Path & "\NameOfYourmdb.mdb;Persist Security Info=False"

'Use for jet
'sSQL = Name Of Your Access table Change to your
'Table Name
sSQL = "TableName"

Set cnn = New ADODB.Connection
Set rs = New ADODB.Recordset
cnn.Open strConn

rs.Open sSQL, cnn, adOpenKeyset, adLockOptimistic, adCmdTable
Do While Len(Range("A" & R).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("Field1") = Range("A" & R).Value
.Fields("Field2") = Range("E" & R).Value
.Fields("Field3") = Range("F" & R).Value
.Fields("Field4") = Range("G" & R).Value

' add more fields if necessary...
.Update ' stores the new record
End With
R = R + 1 ' next row
Loop
rs.Close
cnn.Close

End Sub

"JT" wrote:

> In my Excel macro, I am trying to import a spreadsheet into Access. I create
> an Access object and am trying to use the "transfer spreadsheet" command. It
> works but it is only importing the first line in the spreadsheet.
>
> Below is the code I'm using:
>
> AppAcc.DoCmd.TransferSpreadsheet acImport, 8, "Interest_Table",
> "\\vs300\cost_center\ABC\UploadFile.xls", True
>
> Any ideas or suggestions are greatly appreciated. Thanks for the help......
> --
> JT

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SQL command to access Excel Parrot Microsoft Excel Programming 4 4th Mar 2009 05:08 AM
Access command from Excel JT Microsoft Access VBA Modules 1 19th Nov 2008 08:39 PM
RE: Open Access DB in Excel with Command Button =?Utf-8?B?RGFycmVsbA==?= Microsoft Excel Programming 1 13th Dec 2003 01:28 AM
Re: Open Access DB in Excel with Command Button Bill Manville Microsoft Excel Programming 0 12th Dec 2003 08:11 AM
Re: Using an access command comparable to the excel command "find". Allen Browne Microsoft Access Queries 0 12th Nov 2003 03:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:13 PM.