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
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