On Click event - Create a New Query

C

Craig

Am using using the following code to create a new query - what I would like
to do is if the query name exists, then add in incremental number.
something to the effect of .... if qname already exists then num = num + 1
and qname = "Cqry" & num

Any ideas on how i would work this.

Thanks
Craig

Dim curdatabase As Object
Dim qrydef As Object
Dim qname As String
Dim num As Integer (or should this be string)

num = 1
qname = "Cqry"

Set curdatabase = CurrentDb
Set qrydef = curdatabase.CreateQueryDef(qname, "Select * from tblContact")
DoCmd.OpenQuery qname, acViewDesign, acEdit
 
J

Jeff Boyce

Craig

You've described HOW (automatically create new queries) you are trying to do
something. If you'll describe WHAT you are trying to accomplish, the 'group
readers may be able to offer an alternate approach.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
C

Craig

What I want to accomplish is, by clicking on a button, to open a new query
in design view, with the contact table, and have the query name starting
with Cqry.... (and peferably with user input to finish off naming the
query). If this is not possilbe then the alternative is to have the new
query name in sequence. Cqry1 Cqry2 Cqry3 etc...

As the Database Tables/Forms/Queries are hidden from the user, I want the
ability to create a new query which must be saved with a name starting with
"Cqry"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top