thomas-sherrouse
asked on
Run SQL Update Query From Excel with Parameter VBA
I've got a basic update query that I run from SQL Server Mgnt Studio and I'd like to incorporate it into Excel so that I can type in the parameter that is needed and run it out of Excel. I've been able to incorporate "Select" SQL queries and replace the parameters in the SQL Statement with "?" to create a parameter that is linked to a cell reference, but the same procedure isn't working for an "Update" Statement.
I researched all over and it says I'll probably need to incorporate a bit of VBA Code in order to do this, but I can't quite figure out how to do this.
Here's the Connection String I have that works when I run the "Select" Query:
---
The Command Text I would like to run is:
---
The "?" is normally the Parameter that is pulling the number from Cell "=Sheet1!$C$2"
Please let me know if anyone has any questions or if I can provide any other detail on how best to accomplish this task.
Thanks,
I researched all over and it says I'll probably need to incorporate a bit of VBA Code in order to do this, but I can't quite figure out how to do this.
Here's the Connection String I have that works when I run the "Select" Query:
---
DSN=AvXXnte;Description=Avionte;UID=thoXXX.shXXX;Trusted_Connection=Yes;APP=Microsoft Office 2010;WSID=MAU832N;DATABASE=AvXXnte
---The Command Text I would like to run is:
---
UPDATE TimeEntryBatchError
SET Approve = 1
FROM TimeEntryBatch INNER JOIN
TimeEntryBatchError ON TimeEntryBatch.TimeEntryBatchGUID = TimeEntryBatchError.TimeEntryBatchGUID
WHERE (TimeEntryBatch.BatchID = ?)
---The "?" is normally the Parameter that is pulling the number from Cell "=Sheet1!$C$2"
Please let me know if anyone has any questions or if I can provide any other detail on how best to accomplish this task.
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I had a small error in the solution provided and I was able to troubleshoot and provide a solution to the issue.
ASKER
I'm getting an error of:
Complie error:
User-define type not defined
"cn as New ADODB.Connection" is highlighted as the error.
I'll do some research on the solution but if there is an easy one please let me know .
Thanks