• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Excel VBA : Need help

Tanushri_Kothari

New Member
Hi, need help on excel vba. I have attached an Excel workbook along with Access Database. Password to open the database is 1234. I have placed a button on the excel sheet1. If I click on that button, it should export the data from the access database onto a new excel blank workbook. Please help at your earliest.
 

Attachments

  • Tool.zip
    44.6 KB · Views: 6
Hi:

It can be done without establishing manual connection, but establishing a manual connection is a one minute job. Even if you have multiple users, if the file is shared over the network the link will still work.It is much better than recording the items one-by-one as record set from the data base.

Thanks
 
Hi:

It can be done without establishing manual connection, but establishing a manual connection is a one minute job. Even if you have multiple users, if the file is shared over the network the link will still work.It is much better than recording the items one-by-one as record set from the data base.

Thanks

Thanks Sir, can you plz tell me record set method?
 
Hi:

Please find the attached.
Code:
Sub accessimport()

Dim db As Database
Dim ws As Workspace
Dim acsql As String
Dim recSet As DAO.Recordset

Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase _
("your file path here\myDatabase.mdb", _
    False, False, "MS Access;PWD=1234")
Set recSet = db.OpenRecordset("Raw_Data")
Set rng = Sheet2.Range("A1")
lFieldCount = recSet.Fields.Count

For i = 0 To lFieldCount - 1
rng.Offset(0, i).Value = recSet.Fields(i).Name
Next i
rng.Offset(1, 0).CopyFromRecordset recSet

recSet.Close
Set ws = Nothing
Set db = Nothing

End Sub
you will have to put your file path in the highlighted portion before running the macro.

Thanks
 

Attachments

  • Tool.xlsm
    23.2 KB · Views: 5
Hi:

Please find the attached.
Code:
Sub accessimport()

Dim db As Database
Dim ws As Workspace
Dim acsql As String
Dim recSet As DAO.Recordset

Set ws = DBEngine.Workspaces(0)
Set db = ws.OpenDatabase _
("your file path here\myDatabase.mdb", _
    False, False, "MS Access;PWD=1234")
Set recSet = db.OpenRecordset("Raw_Data")
Set rng = Sheet2.Range("A1")
lFieldCount = recSet.Fields.Count

For i = 0 To lFieldCount - 1
rng.Offset(0, i).Value = recSet.Fields(i).Name
Next i
rng.Offset(1, 0).CopyFromRecordset recSet

recSet.Close
Set ws = Nothing
Set db = Nothing

End Sub
you will have to put your file path in the highlighted portion before running the macro.

Thanks

Hi, sorry for late reply
thank you so much for the great help, it worked perfectly :)
 
Back
Top