cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MisterH
Helper I
Helper I

Running MS Access saved Insert and Update queries

Hi Everyone,

 

I have an MS Access database that I am working with and there are a number of stored parametised queries for inserting and updating records. Is there a way to 'call' these stored queries to add and update records, or am I going to have to grab the SQL from each one and re-create it in PAD? I am not the maintainer of this database so I would very much like to be able to use the saved queries if possible.

Thanks for taking a look at this for me. Any help greatly appreciated.

@MisterH

1 ACCEPTED SOLUTION

Accepted Solutions
MisterH
Helper I
Helper I

Hi Kinuasa,

Thanks for having a crack at this. What you are suggesting is to step outside the flow altogether which defeats the purpose of having the control of the flow.

I have discovered the answer though:

eg/        EXECUTE [yourQueryNameHere] "Some Text Value"

 

The values that you place after the [yourQueryNameHere] need to be in the order they are specified in the query (the one you are calling in MS Access). The data types should also match.

 

eg/         EXECUTE [yourQueryNameHere] "Some Text Value", 123.45, "Another Text Value"

 

I hope this helps anyone else looking to execute queries, particularly parametised ones inside of MS Access.

 

Cheers

 

MisterH

View solution in original post

2 REPLIES 2
kinuasa
Resolver II
Resolver II

Hi,
I suggest that to run a script like the following using the "Run VBScript" action.

 

Regards,
kinuasa

 

Dim con 'ADODB.Connection
Dim cmd 'ADODB.Command
Const DBFilePath = "C:\Test\Sample.accdb"
Const QueryName = "TargetQuery"

Set con = CreateObject("ADODB.Connection")
con.Open "Provider=Microsoft.ACE.OLEDB.16.0;Data Source=" & DBFilePath & ";Persist Security Info=False;"
With CreateObject("ADOX.Catalog")
  Set .ActiveConnection = con
  Set cmd = .Procedures(QueryName).Command
  cmd.Execute
End With
con.Close
MisterH
Helper I
Helper I

Hi Kinuasa,

Thanks for having a crack at this. What you are suggesting is to step outside the flow altogether which defeats the purpose of having the control of the flow.

I have discovered the answer though:

eg/        EXECUTE [yourQueryNameHere] "Some Text Value"

 

The values that you place after the [yourQueryNameHere] need to be in the order they are specified in the query (the one you are calling in MS Access). The data types should also match.

 

eg/         EXECUTE [yourQueryNameHere] "Some Text Value", 123.45, "Another Text Value"

 

I hope this helps anyone else looking to execute queries, particularly parametised ones inside of MS Access.

 

Cheers

 

MisterH

Helpful resources

Announcements
 WHAT’S NEXT AT MICROSOFT IGNITE 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Register for a Free Workshop.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

September Events 2022

Check out all of these events

Attend in person or online, there are incredible conferences and events happening all throughout the month of September.

Top Kudoed Authors
Users online (4,863)