marku24
asked on
VBA script in MS Access calling stored procedure - Invalid Syntax
I am trying to call a stored procedure from SQL server from Access. I know the procedure works fine because I can run in manually, enter the parameters and it writes to the table. I am getting an invalid syntax and assume I am getting my " ' " mixed up. Here it is:
Dim strAssetName As String
Dim strAssetDate As String
Dim strAssetFlag As String
Dim strAssetID As String
Dim sSQL As String
strAssetName = Form_frmDashboard.txtAsset Name.Value
strAssetDate = Form_frmDashboard.txtAsset Date.Value
strAssetFlag = Form_frmDashboard.txtAsset Flag.Value
strAssetID = Form_frmDashboard.txtAsset ID.Value
sSQL = "spAddAssetInventory '" & strAssetName & "' & '" & strAssetDate & "' & '" & strAssetFlag & "' & '" & strAssetID & "'"
DoCmd.RunSQL sSQL
Can anyone help? ~ Thanks
Dim strAssetName As String
Dim strAssetDate As String
Dim strAssetFlag As String
Dim strAssetID As String
Dim sSQL As String
strAssetName = Form_frmDashboard.txtAsset
strAssetDate = Form_frmDashboard.txtAsset
strAssetFlag = Form_frmDashboard.txtAsset
strAssetID = Form_frmDashboard.txtAsset
sSQL = "spAddAssetInventory '" & strAssetName & "' & '" & strAssetDate & "' & '" & strAssetFlag & "' & '" & strAssetID & "'"
DoCmd.RunSQL sSQL
Can anyone help? ~ Thanks
Don't you need to put "EXEC" before the procedure name?
Also, I've just relised you do not seperate your parameters. Normally I would expect the final SQL statement to look something like:
Exec spAddAssetInventory @Asset='ABCD'
ASKER
I get an invalid syntax if I write it like this:
sSQL = "EXEC spAddAssetInventory '" & strAssetName & "' & '" & strAssetDate & "' & '" & strAssetFlag & "' & '" & strAssetID & "'"
sSQL = "EXEC spAddAssetInventory '" & strAssetName & "' & '" & strAssetDate & "' & '" & strAssetFlag & "' & '" & strAssetID & "'"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in your string
with the arguments are separated by &
maybe
Regards
with the arguments are separated by &
strAssetName = "a"
strAssetDate = "b"
strAssetFlag = "c"
strAssetID = "d"
sSQL = "spAddAssetInventory '" & strAssetName & "' & '" & strAssetDate & "' & '" & strAssetFlag & "' & '" & strAssetID & "'"
this givesspAddAssetInventory 'a' & 'b' & 'c' & 'd'
maybe
sSQL = "spAddAssetInventory '" & strAssetName & "' , '" & strAssetDate & "' , '" & strAssetFlag & "' , '" & strAssetID & "'"
Regards
ASKER
awesome!!!!