Stored Procedure (1 Viewer)

gezrod

New member
Local time
Today, 07:00
Joined
May 28, 2017
Messages
5
I have created a stored procedure "UpdateValues" to update 2 columns in a record which matches a specific ID

The stored procedure executes fine in sql manager.

I am trying to execute the stored procedure within access VBA by providing the ID initially and the 2 other parameters which the record will be updated with.

the parameters within the SP are
@ID
@Value1
@Value2
i.e.

the exec command line expects my parameters, but don't know the syntax to use

sql1 = "exec UpdateValues" PARAMETERS TO PASS HERE ?
Cn1.Execute sql1
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:00
Joined
Aug 30, 2003
Messages
36,124
If they're all numeric:

sql1 = "exec UpdateValues 123,456,789"

Text or date/time values get surrounded by single quotes.
 

gezrod

New member
Local time
Today, 07:00
Joined
May 28, 2017
Messages
5
Thanks Pbaldy,

that works a treat with typed values, can I pass values from an access form ?

i.e.

sql1 = "exec UpdateNettTotalTester [id],[val1],[val2]"

Tried it and get syntax error . .
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:00
Joined
Aug 30, 2003
Messages
36,124
You concatenate them into the string:

sql1 = "exec UpdateNettTotalTester " & [id] & ", " & [val1]...
 

gezrod

New member
Local time
Today, 07:00
Joined
May 28, 2017
Messages
5
Thank you again Pbaldy,

I still get a syntax error

sql1 = "exec UpdateNettTotalTester " & [ID] & "," & [Value1] & "," & [Value2]
 

gezrod

New member
Local time
Today, 07:00
Joined
May 28, 2017
Messages
5
Just had a thought the ID is text, the other two are int, what would the syntax be to surround the ID

sql1 = "exec UpdateNettTotalTester " & [ID] & "," & [Value1] & "," & [Value2]
 

gezrod

New member
Local time
Today, 07:00
Joined
May 28, 2017
Messages
5
Sorted it, thank you pbaldy,

sql1 = "exec UpdateNettTotalTester " & "'" & [ID] & "'" & "," & [Value1] & "," & [Value2]

thank you again
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:00
Joined
Aug 30, 2003
Messages
36,124
Add an apostrophe on either side of the value, inside the quotes.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 07:00
Joined
Aug 30, 2003
Messages
36,124
Ah, glad you got it sorted.
 

Users who are viewing this thread

Top Bottom