LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Access Table into Excel using VB

I am trying to automate import of an Access Table into Excel for further use.
I have tried the code below from a previous post but get an immediate error
on the first 2 Dim statements. The Database is called "Pressing Database.mdb"
and the table is called "Used Felt". Ihave only listed 4 of the columns for
brevity but there are many more.
Thanks for any help
Steve

Private Sub QueryAccessDB()

Dim cnn As ADODB.Connection
Dim rs1 As ADODB.Recordset
Dim strSQL1 As String, strConn
Dim i As Integer

i = 1

'Use for Access (jet)
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=\\Jns-dc01\kandbreplica\" _
& "Pressing Database.mdb;Persist Security Info=False"
MyTable = "Used Felt"
'Use for jet
strSQL1 = "SELECT MyTable.MillCode, MyTable.Machine, MyTable.Position ,
" _
& "MyTable.PositionName, " _
& "FROM MyTable; "


Set cnn = New ADODB.Connection
Set rs1 = New ADODB.Recordset
cnn.Open strConn
rs1.Open strSQL1, cnn, adOpenForwardOnly, adLockReadOnly
Do While rs1.EOF = False
Sheets("Sheet1").Range("A" & i) = rs1!MillCode
Sheets("Sheet1").Range("B" & i) = rs1!Machine
Sheets("Sheet1").Range("C" & i) = rs1!Position
Sheets("Sheet1").Range("D" & i) = rs1!PositionName
' Sheets("Sheet1").Range("E" & i) = rs1!FIELDNAME5
' Sheets("Sheet1").Range("F" & i) = rs1!FIELDNAME6
' Sheets("Sheet1").Range("G" & i) = rs1!FIELDNAME7
' Sheets("Sheet1").Range("H" & i) = rs1!FIELDNAME8
i = i + 1
rs1.MoveNext
Loop
rs1.Close
cnn.Close
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
HELP linking access table to excel greg Excel Worksheet Functions 3 July 30th 08 03:29 PM
Import Access Table into Excel Irishimp23 Excel Worksheet Functions 3 June 21st 07 04:50 PM
How to retrieve the value within the table from Access into Excel? Eric Excel Discussion (Misc queries) 1 April 18th 06 09:19 PM
Data from Excel to Access Table Secret Squirrel Excel Discussion (Misc queries) 11 December 2nd 05 11:58 PM
Excel Pivot Table with Access ExcelQuestions Excel Discussion (Misc queries) 0 April 11th 05 03:37 PM


All times are GMT +1. The time now is 08:21 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"