Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read existing querydef object in a mdb that require parameters

Status
Not open for further replies.

thomasyu

Programmer
Jun 22, 2001
15
0
0
HK
I already define a querydef called ABCDelete in MS Access mdb which have the following definition.
PARAMETERS [param1] date, [param2] text;
DELETE FROM ......

How can I execute and supply the parameters by means of DAO in VB or VBA?
The following cause runtime error at the CreateQueryDef
- too few parameters, expected ...
If I add something extra more than ABCDelete, the following error occurs
- The database engine cannot find the table, query, ...

Dim myqry as dao.querydef
set myqry = mydb.createquerydef("ABCDelete")
with myqry.parameters
!param1.value = ...
!param2.value = ...

If I ignore the existing QueryDef object in MSAcess and create a temp querydef by repeating the defintion of the querydef as follow, everything works fine.

Dim myqry as dao.querydef
Dim mySQL as string
mySQL = "PARAMETERS [param1] date, [param2] text;" & _
"DELETE FROM ......"
set myqry = mydb.createquerydef(mySQL)
with myqry.parameters
!param1.value = ...
!param2.value = ...
 
Dim myqry as dao.querydef
set myqry = mydb.createquerydef("ABCDelete")
with myqry.parameters
!param1.value = ...
!param2.value = ...

set myqry = mydb.querydefs("ABCDelete")

Should get one step closer. I'm chasing myself out of here, so probably no more answeres from me today




MichaelRed
redmsp@erols.com

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top