Run-time error where 'object already exists'

S

Sheryl

I have a dialog box that has 3 list boxes that are multi select, plus and/or
choices between them that supplies my query, 'qryPickAChecker', then should
run my query. The code seems to be hanging up at this area
cat.Views.Append "qryPickAChecker", cmd
and it gives me:
run-time error '-2147217816 (80040e68)': Object 'qryPickAChecker' already
exists.

I'm am stuck and don't know what to do to fix this. Here is my code to that
point.
Private Sub cmdOK_Click()

Dim blnQueryExists As Boolean
Dim cat As New ADOX.Catalog
Dim cmd As New ADODB.Command
Dim qry As ADOX.View
Dim varItem As Variant
Dim strLast As String
Dim strFirst As String
Dim strCkrCDSID As String
Dim strFirstCondition As String
Dim strCkrCDSIDCondition As String
Dim strSQL As String
' Check for the existence of the stored query
blnQueryExists = False
Set cat.ActiveConnection = CurrentProject.Connection
For Each qry In cat.Views
If qry.Name = "qryPickAChecker" Then
blnQueryExists = True
Exit For
End If
Next qry
' Create the query if it does not already exist
If blnQueryExists = False Then
cmd.CommandText = "SELECT * FROM tblChecker"
cat.Views.Append "qryPickAChecker", cmd
End If
Application.RefreshDatabaseWindow
' Turn off screen updating
DoCmd.Echo False
' Close the query if it is already open
If SysCmd(acSysCmdGetObjectState, acQuery, "qryPickAChecker") =
acObjStateOpen Then
DoCmd.Close acQuery, "qryPickAChecker"
End If
 
D

Douglas J. Steele

You haven't accidentally used that name for some other object than a query,
have you?
 
S

Sheryl

Doug,

I didn't find anything under the name "qryPickAChecker' in my entire
database except the query it's going to send the choices to. Any clues what
I can do now?
 
D

Douglas J. Steele

The only thing that occurs to me off the top of my head would be to see
whether compacting the database helps.
 

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