Creating a query from a form

C

Craig

Reworking a previous entry:

I have a cmdbutton in a form with the following code: This appears to work
except an error occurs if the same name of an existing query is input into
the InputBox more than twice.

Run-time Error 3012 : Object 'Cqry' already exists.

Why doesnt the error handler not pass the second time around?
How can I check for the existance of a query name?

Thanks
Craig


Private Sub Command185_Click()
On Error GoTo Err_Command185_Click
Dim curdatabase As Object
Dim qrydef As Object
Dim qname As String
Dim qdf As QueryDef

qname = InputBox("Enter a name for this Query", "New Query", "Cqry")

TestName:
If Left(qname, 4) <> "Cqry" Then
qname = InputBox("Query name is not valid. Input another name.", "New
Query", "Cqry")
GoTo TestName
End If

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

Exit_Command185_Click:
Exit Sub

Err_Command185_Click:
qname = InputBox("Query name already exist. Input another name.", "New
Query", "Cqry")
GoTo TestName
Resume Exit_Command185_Click

End Sub
 
E

eos

AUTO-REPLY From George Levitt

Please allow this to confirm a system receipt of your e-mail.

I am out of the office until Wednesday morning (1/12/05) and will not be
reviewing or responding to email or voicemail until that time.

I look forward to replying to your message on Wednesday.

Thanks and warmest regards, George
 

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