VBA Oracle Query with Parameters

mholman

New Member
Joined
Jun 5, 2009
Messages
4
Hi, I'm trying to run a query with VBA to connect to an Oracle database, but am running into issues when I try to add in a parameter. This statement is essentially what I'm trying to run, but I can't figure out how to put in a parameter:
Code:
SELECT * FROM database WHERE MY_COLUMN=myparam
(where myparam is a parameter

This is the code I'm trying, but it throws errors:
Code:
query.CommandText = "SELECT * FROM database WHERE MY_COLUMN=myparam"
query.CommandType = adCmdText
' is this wrong? I'm trying for it to be a 5 char long string
query.Parameters.Append query.CreateParameter("myparam", adChar, adParamInput, 5, cell.Value)
oracleConnection.Open mConnectionString
query.ActiveConnection = oracleConnection
Set rst = query.Execute
...
It looks like it is trying to find the column myvar in the database and not using it as a parameter. I know I probably need to throw an identifier in the connection string so it knows to use it as a parameter, but I don't know what it would be, and google has surprisingly little on using actual parameters in VBA.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
Anyone know how to do this? I'm still stuck here. I've tried using all sorts of delimiters, but just can't get it to work. I'm sure it's something really simple, but I just can't figure it out or find any documentation that helps me.
 
Upvote 0

Forum statistics

Threads
1,222,625
Messages
6,167,149
Members
452,099
Latest member
Auroraaa

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