VBA Access Query

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Setting up a VBA query to connect and retrieve data from an access database:

Access Database named: JTAccess
Query in Access Database name: A_Generic
field:
entity: 222
posting year: 2019
Account: 1200000

How can I setup a VBA code to retrieve this data:

I setup references:
And setup the following VBA code:


sub copyaccess()
dim jtconnection as ADODB.connection
dim jtrecord as adodb.recordset
dim headerdata as adodb.field


const Sresource as string = "Provider=Microsoft.ACE.OLEDB.12.0;Data source= "S\:JTaccess.accdb; Persist security info=false"

set jtconnection = new adodb.connection
set jtrecord = new Adodb.recordset

jtconnection.connectionstring = Sresource
jtconnection.open

with jtrecord
.activeconnection = jtconnection
.source = getaccessstring

.open
end with
worksheets.add

end sub

function getaccessstring
accessstring = ([entity] =222, [posting year] = 2019; [account] = 1200000)

end sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,215,366
Messages
6,124,514
Members
449,168
Latest member
CheerfulWalker

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