Import data from Access 2007

  • Thread starter Thread starter Johnnie
  • Start date Start date
J

Johnnie

I need to link data from Access 2007 into my Excel 2007 worksheet. That
seems simple enough, but I don't want to include the column headers from the
Access database. Is there a way to link to the data and NOT bring in the
column headers? Thanks! Johnnie
 
Hi Johnnie

Try out the below method using ADODB.

Sub ExtractFromAccess()
Dim strDB As String, lngRow As Long
Dim con As New ADODB.Connection, rs As New ADODB.Recordset

strDB = "C:\opstats.mdb"
con.Open "DBQ=" & strDB & ";Driver={Microsoft Access Driver (*.mdb)}"
rs.CursorLocation = adUseClient
rs.Open "select * from opmast", con, adOpenDynamic
'---------------------------------
lngRow = 1
Do While rs.EOF = False
Range("A" & lngRow) = rs("opid")
Range("B" & lngRow) = rs("opname")
lngRow = lngRow + 1
rs.MoveNext
Loop
'---------------------------------
rs.Close: con.Close
Set rs = Nothing: Set con = Nothing
End Sub

If this post helps click Yes
 
Back
Top