Excel macro to import data from access query

mawama

New Member
Joined
Jul 31, 2013
Messages
22
Hello,

Someone to help with the excel macro to import data from access query to the excel sheet 1.

The access Query has been constrained with date parameter criteria as "Between[Date From] And [Date To]"

Note this date to be taken or referred from excel sheet 1 on cell H3 (date from) and H4 (date to)

A excel macro able to clear out excel sheet 1 on column A1 to F100 and paste the new access query data to the excel column A1 to F100

I don't have issue with access querry BUT need to import the data from it to excel as detailed above.

I will really appreciate for someone to help, got stack and don't know who to get it working.

Cheers,

Mawama
 
Last edited:

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Give this s try
VBA Code:
Sub ImportFromAccess()

    Dim objADO As Object
    Dim objRec As Object
    
    Set objADO = CreateObject("ADODB.Connection")
    
    With objADO
        .Provider = "Microsoft.ACE.OLEDB.12.0"
        .Properties("Data Source") = "C:\YourDatabase.mdb"
        .Open
    End With
    
    Set objRec = objADO.Execute("SELECT * FROM your_table_name")
    
    With Sheets("Sheet1").Range("A1")
        .Resize(100, 6).ClearContents
        .CopyFromRecordset objRec, 100
    End With
    
    objADO.Close

End Sub
 
Upvote 0
Hello Juddaaaa,

Thanks for the feedback, I have put the macro but yet get stack with the message that "no value given for one or more required parameters" I believe this is associated with the Between (dateFROM) And (dateTO) in my access query.

In my excel these parameters are located in J2 for DateFrom and J3 for DateTo

Please check and advise mate.

Regards,
Mawama
 

Attachments

  • Image1.PNG
    Image1.PNG
    11.4 KB · Views: 5
  • Image2.PNG
    Image2.PNG
    20.8 KB · Views: 5
Upvote 0
As my access query has date range parameters and these are what missing in this code, please check and advise mate.
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top