
Union query gives 'Too few parameters'
Hi,
I am trying to call an update query in MSAccess from a VB6 program using an
ADODB command object.
The technique I am using works fine for 'normal' queries, but if my query
contains UNIONs then I get the message:
'Run-time error '-2147217904' [Microsoft][ODBC Microsoft Access Driver]
Too few parameters
expected n'
I have noticed that the number of parameters expected (n) is the same as the
number of different UNIONS in my query.
note that in the examples below, I have stripped the queries down to the
bare minimum that still exhibits the problem.
If anyone has got any idea how to get round this I will be most grateful.
Thanks in anticipation of your response
Chris.
VBCode:
======
Private Sub Command1_Click()
Dim conAccess as ADODB.Connection
Dim cmdDoIt As New ADODB.Command
Dim strAccessConnect As String
strAccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=plu.mdb;" & _
"DefaultDir=C:\tmp;" & _
"Uid=Admin;Pwd=0861;"
conAccess.ConnectionString = strAccessConnect
conAccess.Open
cmdDoIt.ActiveConnection = conAccess
cmdDoIt.CommandType = adCmdText
cmdDoIt.CommandText = "execute Append_PLUs"
cmdDoIt.Execute
Access Queries:
===========
This works fine.
select *
from mytable
where myfield="1"
This fails with 'Too few parameters, expected 2':
select *
from mytable
where myfield="1"
union all
select *
from mytable
where myfield="2"