Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am trying to create a program that can import excel data straight into an access table

What I have tried:

Sub AccParam() 'Excel VBA to import a parameter query from Access into Excel
Dim MyDatabase As DAO.database
Dim MyQueryDef As DAO.QueryDef
Dim MyRecordset As DAO.Recordset

Set MyDatabase = DBEngine.OpenDatabase("C:\Users\User\Desktop\rtu\1 kurss\Datubāzes\db6\DB6.accdb") 'DB Name
Set MyQueryDef = MyDatabase.QueryDefs("qryStates") 'Query Name

Sheet1.Range("A11:T100").ClearContents 'Range to Clear
MyQueryDef.Parameters("[ChooseRegion]") = Sheet1.[f6].Value
Set MyRecordset = MyQueryDef.OpenRecordset 'Open the query
Sheet1.Range("A11").CopyFromRecordset MyRecordset

End Sub
Posted
Updated 31-May-19 16:48pm

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900