Consulting

Results 1 to 5 of 5

Thread: Solved: Please help me compile this code

  1. #1

    Solved: Please help me compile this code

    This code is supposed to import from Access to Excel:

    [vba]Sub AccessToExcel()
    Dim dbConnection As ADODB.Connection
    Dim dbRecordset As ADODB.Recordset
    Dim dbFileName As String
    Dim strSQL As String
    Dim DestinationSheet As Worksheet
    Set dbConnection = New ADODB.Connection
    Set dbRecordset = New ADODB.Recordset
    Set DestinationSheet = Worksheets("Sheet2")
    dbFileName = "C:\Documents and Settings\ADRY_7258\My Documents\Test_Access_db.accdb"
    dbConnection.Provider = "Microsoft.ACE.OLEDB.12.0;Data Source=" & dbFileName _
    & ";Persist Security Info=False;"

    strSQL = "SELECT Test_Access_db.* from Test_Access_db;"

    DestinationSheet.Cells.Clear

    With dbConnection
    .Open
    .Cursorlocation = adUseClinet
    End With

    With dbRecordset
    .Open strSQL, dbConnection
    Set ActiveConnection = Nothing
    DestinationSheet.Range("A2").CopyFromRecordset dbRecordset
    DestinationSheet.Range("A1:C1").Value = Array("Employee ID", "Employee Name", "Employee Salary")

    dbRecordset.Close
    dbConnection.Close

    Set dbRecordset = Nothing
    Set dbConnection = Nothing
    Set DestinationSheet = Nothing
    End Sub[/vba]
    Last edited by Aussiebear; 08-15-2011 at 11:57 PM. Reason: Added vba tags to code

  2. #2

    Please issue earlier post

    The matter has been resolved.

    Thanks.

  3. #3
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    So, was the issue, how to compile or an error resulting from a compile attempt?
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Maybe something to do with this Ted
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,060
    Location
    So it seems. I was misled by the thread title.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •