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
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