Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

docmd.copyobject for copying query in code

194 views
Skip to first unread message

Jamie Bond

unread,
Oct 17, 2002, 6:33:39 AM10/17/02
to
I am having difficulty using the docmd.copyobject within
code to copy an existing query to create a new query with
a new name. below is the line in question

DoCmd.CopyObject myDB, sNewQueryName,
acQuery, "qryGenericIDDates"

i have public declared myDB as Database and set it to
CurrentDB, sNewQueryName is a string containing the name
of the query I want created and qryGenericIDDates is the
existing query in the database

when running this line of code it always errors
with "2498 - an expression you entered is the wrong data
type for one of the arguments"?

could someone please tell me what I am doing wrong?

Jamie

Sandra Daigle

unread,
Oct 17, 2002, 7:56:22 AM10/17/02
to
Hi Jamie,

The first parameter should be a string that's the valid path and file name
for the database you want to copy the object into. You can leave this
parameter blank if you are copying into the current database.

DoCmd.CopyObject , sNewQueryName, acQuery, "qryGenericIDDates"

or since the name property of the database object contains the full path and
file name of the mdb (if myDb is referring to a different database)

DoCmd.CopyObject myDB.name, sNewQueryName, acQuery, "qryGenericIDDates"

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

John Spencer (MVP)

unread,
Oct 17, 2002, 8:07:58 AM10/17/02
to
The first argument should be a STRING.

QUOTE from online help
Destination Database - A string expression that's the valid path and file name
for the database you want to copy the object into. To select the current
database, leave this argument blank.
END QUOTE

So try:

DoCmd.CopyObject , sNewQueryName,acQuery,"qryGenericIDDates"
or
DoCmd.CopyObject myDb.Name, sNewQueryName,acQuery,"qryGenericIDDates"

jamie_...@hotmail.com

unread,
Oct 17, 2002, 8:40:23 AM10/17/02
to
cheers guys

>.
>

0 new messages