DH QBF

  • Thread starter Secret Squirrel
  • Start date
S

Secret Squirrel

I'm getting an error message all of a sudden using the DH QBF. It has worked
all along but now for some reason it's erroring out. Can anyone help with
this?

Run Time Error: 3012
Object 'MyQuery' already exists.

Nothing has been changed so I don't know why it's not working. I also
downloaded the orginal QBF to test it and the same thing happens with that
one. I wonder if there is something wrong internally with Access.
 
R

Ron Hinds

It sounds like that is a query that is created on the fly in code and
deleted when no longer needed. Access probably crashed or was stopped for
debugging, etc., before the query was deleted. You can delete it manually
from the query tab of the database window and it should work again. In order
to keep this problem from recurring, I would suggest modifying the code so
that when the routine that uses this query exits it is automatically
deleted, like so:

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.
 
S

Secret Squirrel

Why would it all of a sudden do that? Is there something wrong with Access? I
added the code but it didn't work. Now I'm getting this error message:

Method or data member not found:
*The expression may not result in the name of a macro, the name of a user
defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro
 
R

Ron Hinds

Secret Squirrel said:
Why would it all of a sudden do that? Is there something wrong with
Access?

As I explained below, it was probably inadvertently not deleted due to a
system crash or an error of some sort in the routine that creates/deletes
the query. That is why I use the code snippet I gave you in all of my
routines where I create QueryDefs on the fly.
I
added the code but it didn't work. Now I'm getting this error message:

Method or data member not found:
*The expression may not result in the name of a macro, the name of a user
defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro

That's odd because the statement

On Error Resume Next

should cause no error messages! Please post the *entire* routine you are
using this in and I'll see if I can't figure out what is wrong.
 
S

Secret Squirrel

Here is the code for that specific function:

Private Sub cmdReport_Click()
On Error GoTo cmdReport_Click_Err
Dim strFields As String
Dim strWhere As String
Dim strFrom As String
Dim strOrderBy As String
Dim strGroupBy As String
Dim booTotals As Boolean
Dim strQueryName As String
Dim qdUserQuery As DAO.QueryDef
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim I As Integer
Dim strSQL As String
Me![sfrmQBFFields].Form.Requery
Set rs = Me![sfrmQBFFields].Form.RecordsetClone
rs.MoveLast
I = rs.RecordCount
rs.MoveFirst

Dim strDelim As String
Set db = DBEngine.Workspaces(0).Databases(0)
strFrom = " From [" & Me![cboSource] & "]"
booTotals = Me.chkTotals = True
For I = 1 To I
If booTotals And rs("qbfTotal") & "" = "" Then
MsgBox "You must select an option in the Total " & _
"column for each field when using Totals.", _
vbInformation + vbOKOnly, "Select All Totals"
Exit Sub
End If
If Not IsNull(rs("QBFField")) Then
If booTotals = True Then
Select Case rs("qbfTotal")
Case "Sum", "Count", "Avg", "Min", "Max"
'rs("qbfTotal") should be one of the above aggregates
strFields = strFields & rs("qbfTotal") & "([" &
rs!QBFField & _
"]) as [" & rs("qbfTotal") & "_" & rs!QBFField &
"] , "
Case "Group By"
strGroupBy = strGroupBy & "[" & rs!QBFField & "], "
strFields = strFields & "[" & rs!QBFField & "], "
End Select
Else
strFields = strFields & "[" & rs!QBFField & "], "
End If
End If
If Not IsNull(rs!Operator) Then
strDelim = rs!Delimiter
strWhere = strWhere & "[" & rs!QBFField & "] " & rs!Operator
Select Case rs!Operator
Case "IN"
strWhere = strWhere & "( " & strDelim & rs!Value1 &
strDelim & ")" & " AND "
Case "Is Null"
strWhere = strWhere & " AND "
Case Else
strWhere = strWhere & strDelim & rs!Value1 & strDelim & "
AND "
End Select


If rs!Operator = "Between" Then
strWhere = strWhere & strDelim & rs!Value2 & strDelim & "
AND "
End If
End If
If Len(rs!SortOrder & "") > 0 Then
If rs!SortOrder <> "N" Then
strOrderBy = strOrderBy & "[" & rs!QBFField & "], "
End If
End If
rs.MoveNext
Next
If Len(strFields) > 2 Then
strFields = left$(strFields, Len(strFields) - 2)
End If
If Len(strWhere) > 5 Then
strWhere = " Where " & left$(strWhere, Len(strWhere) - 4)
End If
If Len(strOrderBy) > 0 Then
strOrderBy = " Order By " & left$(strOrderBy, Len(strOrderBy) - 2)
End If
If Len(strGroupBy) > 0 Then
strGroupBy = " Group By " & left$(strGroupBy, Len(strGroupBy) - 2)
strOrderBy = ""
End If

strSQL = "Select " & strFields & strFrom & strWhere & strGroupBy &
strOrderBy & " ;"
rs.Close
'MsgBox strSQL
strQueryName = "MyQuery"
Set qdUserQuery = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh

DoCmd.OpenForm "frmMyQueryResults", , , , , , strQueryName

cmdReport_Click_Exit:
On Error Resume Next
Exit Sub

cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

End Sub

Ron Hinds said:
Secret Squirrel said:
Why would it all of a sudden do that? Is there something wrong with
Access?

As I explained below, it was probably inadvertently not deleted due to a
system crash or an error of some sort in the routine that creates/deletes
the query. That is why I use the code snippet I gave you in all of my
routines where I create QueryDefs on the fly.
I
added the code but it didn't work. Now I'm getting this error message:

Method or data member not found:
*The expression may not result in the name of a macro, the name of a user
defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro

That's odd because the statement

On Error Resume Next

should cause no error messages! Please post the *entire* routine you are
using this in and I'll see if I can't figure out what is wrong.
 
R

Ron Hinds

OK - here's what you need to do. Remove the lines you added to the end of
the function. Then change the following after the label
cmdReport_Click_Exit:

cmdReport_Click_Exit:
On Error Resume Next
CurrentDb.QueryDefs.Delete "MyQuery"
Exit Sub

That should guarantee that "MyQuery" will be deleted every time even if
there is an error in cmdReport_Click.

Secret Squirrel said:
Here is the code for that specific function:

Private Sub cmdReport_Click()
On Error GoTo cmdReport_Click_Err
Dim strFields As String
Dim strWhere As String
Dim strFrom As String
Dim strOrderBy As String
Dim strGroupBy As String
Dim booTotals As Boolean
Dim strQueryName As String
Dim qdUserQuery As DAO.QueryDef
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim I As Integer
Dim strSQL As String
Me![sfrmQBFFields].Form.Requery
Set rs = Me![sfrmQBFFields].Form.RecordsetClone
rs.MoveLast
I = rs.RecordCount
rs.MoveFirst

Dim strDelim As String
Set db = DBEngine.Workspaces(0).Databases(0)
strFrom = " From [" & Me![cboSource] & "]"
booTotals = Me.chkTotals = True
For I = 1 To I
If booTotals And rs("qbfTotal") & "" = "" Then
MsgBox "You must select an option in the Total " & _
"column for each field when using Totals.", _
vbInformation + vbOKOnly, "Select All Totals"
Exit Sub
End If
If Not IsNull(rs("QBFField")) Then
If booTotals = True Then
Select Case rs("qbfTotal")
Case "Sum", "Count", "Avg", "Min", "Max"
'rs("qbfTotal") should be one of the above aggregates
strFields = strFields & rs("qbfTotal") & "([" &
rs!QBFField & _
"]) as [" & rs("qbfTotal") & "_" & rs!QBFField &
"] , "
Case "Group By"
strGroupBy = strGroupBy & "[" & rs!QBFField & "], "
strFields = strFields & "[" & rs!QBFField & "], "
End Select
Else
strFields = strFields & "[" & rs!QBFField & "], "
End If
End If
If Not IsNull(rs!Operator) Then
strDelim = rs!Delimiter
strWhere = strWhere & "[" & rs!QBFField & "] " & rs!Operator
Select Case rs!Operator
Case "IN"
strWhere = strWhere & "( " & strDelim & rs!Value1 &
strDelim & ")" & " AND "
Case "Is Null"
strWhere = strWhere & " AND "
Case Else
strWhere = strWhere & strDelim & rs!Value1 & strDelim & "
AND "
End Select


If rs!Operator = "Between" Then
strWhere = strWhere & strDelim & rs!Value2 & strDelim & "
AND "
End If
End If
If Len(rs!SortOrder & "") > 0 Then
If rs!SortOrder <> "N" Then
strOrderBy = strOrderBy & "[" & rs!QBFField & "], "
End If
End If
rs.MoveNext
Next
If Len(strFields) > 2 Then
strFields = left$(strFields, Len(strFields) - 2)
End If
If Len(strWhere) > 5 Then
strWhere = " Where " & left$(strWhere, Len(strWhere) - 4)
End If
If Len(strOrderBy) > 0 Then
strOrderBy = " Order By " & left$(strOrderBy, Len(strOrderBy) - 2)
End If
If Len(strGroupBy) > 0 Then
strGroupBy = " Group By " & left$(strGroupBy, Len(strGroupBy) - 2)
strOrderBy = ""
End If

strSQL = "Select " & strFields & strFrom & strWhere & strGroupBy &
strOrderBy & " ;"
rs.Close
'MsgBox strSQL
strQueryName = "MyQuery"
Set qdUserQuery = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh

DoCmd.OpenForm "frmMyQueryResults", , , , , , strQueryName

cmdReport_Click_Exit:
On Error Resume Next
Exit Sub

cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

End Sub

Ron Hinds said:
Secret Squirrel said:
Why would it all of a sudden do that? Is there something wrong with
Access?

As I explained below, it was probably inadvertently not deleted due to a
system crash or an error of some sort in the routine that creates/deletes
the query. That is why I use the code snippet I gave you in all of my
routines where I create QueryDefs on the fly.
I
added the code but it didn't work. Now I'm getting this error message:

Method or data member not found:
*The expression may not result in the name of a macro, the name of a user
defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro

That's odd because the statement

On Error Resume Next

should cause no error messages! Please post the *entire* routine you are
using this in and I'll see if I can't figure out what is wrong.
:

It sounds like that is a query that is created on the fly in code and
deleted when no longer needed. Access probably crashed or was
stopped
for
debugging, etc., before the query was deleted. You can delete it manually
from the query tab of the database window and it should work again.
In
order
to keep this problem from recurring, I would suggest modifying the
code
so
that when the routine that uses this query exits it is automatically
deleted, like so:

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

message I'm getting an error message all of a sudden using the DH QBF. It has
worked
all along but now for some reason it's erroring out. Can anyone
help
with
this?

Run Time Error: 3012
Object 'MyQuery' already exists.

Nothing has been changed so I don't know why it's not working. I also
downloaded the orginal QBF to test it and the same thing happens
with
that
one. I wonder if there is something wrong internally with Access.
 
S

Secret Squirrel

Ok I tried that and now I get this error messge:

Run-time error '3265':
Item not found in this collection

Ron Hinds said:
OK - here's what you need to do. Remove the lines you added to the end of
the function. Then change the following after the label
cmdReport_Click_Exit:

cmdReport_Click_Exit:
On Error Resume Next
CurrentDb.QueryDefs.Delete "MyQuery"
Exit Sub

That should guarantee that "MyQuery" will be deleted every time even if
there is an error in cmdReport_Click.

Secret Squirrel said:
Here is the code for that specific function:

Private Sub cmdReport_Click()
On Error GoTo cmdReport_Click_Err
Dim strFields As String
Dim strWhere As String
Dim strFrom As String
Dim strOrderBy As String
Dim strGroupBy As String
Dim booTotals As Boolean
Dim strQueryName As String
Dim qdUserQuery As DAO.QueryDef
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim I As Integer
Dim strSQL As String
Me![sfrmQBFFields].Form.Requery
Set rs = Me![sfrmQBFFields].Form.RecordsetClone
rs.MoveLast
I = rs.RecordCount
rs.MoveFirst

Dim strDelim As String
Set db = DBEngine.Workspaces(0).Databases(0)
strFrom = " From [" & Me![cboSource] & "]"
booTotals = Me.chkTotals = True
For I = 1 To I
If booTotals And rs("qbfTotal") & "" = "" Then
MsgBox "You must select an option in the Total " & _
"column for each field when using Totals.", _
vbInformation + vbOKOnly, "Select All Totals"
Exit Sub
End If
If Not IsNull(rs("QBFField")) Then
If booTotals = True Then
Select Case rs("qbfTotal")
Case "Sum", "Count", "Avg", "Min", "Max"
'rs("qbfTotal") should be one of the above aggregates
strFields = strFields & rs("qbfTotal") & "([" &
rs!QBFField & _
"]) as [" & rs("qbfTotal") & "_" & rs!QBFField &
"] , "
Case "Group By"
strGroupBy = strGroupBy & "[" & rs!QBFField & "], "
strFields = strFields & "[" & rs!QBFField & "], "
End Select
Else
strFields = strFields & "[" & rs!QBFField & "], "
End If
End If
If Not IsNull(rs!Operator) Then
strDelim = rs!Delimiter
strWhere = strWhere & "[" & rs!QBFField & "] " & rs!Operator
Select Case rs!Operator
Case "IN"
strWhere = strWhere & "( " & strDelim & rs!Value1 &
strDelim & ")" & " AND "
Case "Is Null"
strWhere = strWhere & " AND "
Case Else
strWhere = strWhere & strDelim & rs!Value1 & strDelim & "
AND "
End Select


If rs!Operator = "Between" Then
strWhere = strWhere & strDelim & rs!Value2 & strDelim & "
AND "
End If
End If
If Len(rs!SortOrder & "") > 0 Then
If rs!SortOrder <> "N" Then
strOrderBy = strOrderBy & "[" & rs!QBFField & "], "
End If
End If
rs.MoveNext
Next
If Len(strFields) > 2 Then
strFields = left$(strFields, Len(strFields) - 2)
End If
If Len(strWhere) > 5 Then
strWhere = " Where " & left$(strWhere, Len(strWhere) - 4)
End If
If Len(strOrderBy) > 0 Then
strOrderBy = " Order By " & left$(strOrderBy, Len(strOrderBy) - 2)
End If
If Len(strGroupBy) > 0 Then
strGroupBy = " Group By " & left$(strGroupBy, Len(strGroupBy) - 2)
strOrderBy = ""
End If

strSQL = "Select " & strFields & strFrom & strWhere & strGroupBy &
strOrderBy & " ;"
rs.Close
'MsgBox strSQL
strQueryName = "MyQuery"
Set qdUserQuery = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh

DoCmd.OpenForm "frmMyQueryResults", , , , , , strQueryName

cmdReport_Click_Exit:
On Error Resume Next
Exit Sub

cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

End Sub

Ron Hinds said:
message Why would it all of a sudden do that? Is there something wrong with
Access?

As I explained below, it was probably inadvertently not deleted due to a
system crash or an error of some sort in the routine that creates/deletes
the query. That is why I use the code snippet I gave you in all of my
routines where I create QueryDefs on the fly.

I
added the code but it didn't work. Now I'm getting this error message:

Method or data member not found:
*The expression may not result in the name of a macro, the name of a user
defined function, or [Event Procedure]
*There may have been an error evaluating the function, event, or macro

That's odd because the statement

On Error Resume Next

should cause no error messages! Please post the *entire* routine you are
using this in and I'll see if I can't figure out what is wrong.


:

It sounds like that is a query that is created on the fly in code and
deleted when no longer needed. Access probably crashed or was stopped
for
debugging, etc., before the query was deleted. You can delete it
manually
from the query tab of the database window and it should work again. In
order
to keep this problem from recurring, I would suggest modifying the code
so
that when the routine that uses this query exits it is automatically
deleted, like so:

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

message I'm getting an error message all of a sudden using the DH QBF. It has
worked
all along but now for some reason it's erroring out. Can anyone help
with
this?

Run Time Error: 3012
Object 'MyQuery' already exists.

Nothing has been changed so I don't know why it's not working. I also
downloaded the orginal QBF to test it and the same thing happens with
that
one. I wonder if there is something wrong internally with Access.
 
S

Secret Squirrel

I tried the compact and repair....didn't work

I downloaded the original database with this code and the same problem
existed. This has worked for a while but all of a sudden it started getting
this error message

I check the references and they are all ok. None of them say MISSING.

So am I missing something?


Van T. Dinh said:
* Have you tried Compact & Repair?

* Have you recompiled the code? It sounds like you have compilation errors.

* Have you checked the References Collection and see whether any Refernce is
marked as MISSING? A missing Reference or errors in the References
collection often give the error messages you got.

--
HTH
Van T. Dinh
MVP (Access)



Secret Squirrel said:
Here is the code for that specific function:

Private Sub cmdReport_Click()
On Error GoTo cmdReport_Click_Err
Dim strFields As String
Dim strWhere As String
Dim strFrom As String
Dim strOrderBy As String
Dim strGroupBy As String
Dim booTotals As Boolean
Dim strQueryName As String
Dim qdUserQuery As DAO.QueryDef
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim I As Integer
Dim strSQL As String
Me![sfrmQBFFields].Form.Requery
Set rs = Me![sfrmQBFFields].Form.RecordsetClone
rs.MoveLast
I = rs.RecordCount
rs.MoveFirst

Dim strDelim As String
Set db = DBEngine.Workspaces(0).Databases(0)
strFrom = " From [" & Me![cboSource] & "]"
booTotals = Me.chkTotals = True
For I = 1 To I
If booTotals And rs("qbfTotal") & "" = "" Then
MsgBox "You must select an option in the Total " & _
"column for each field when using Totals.", _
vbInformation + vbOKOnly, "Select All Totals"
Exit Sub
End If
If Not IsNull(rs("QBFField")) Then
If booTotals = True Then
Select Case rs("qbfTotal")
Case "Sum", "Count", "Avg", "Min", "Max"
'rs("qbfTotal") should be one of the above
aggregates
strFields = strFields & rs("qbfTotal") & "([" &
rs!QBFField & _
"]) as [" & rs("qbfTotal") & "_" & rs!QBFField
&
"] , "
Case "Group By"
strGroupBy = strGroupBy & "[" & rs!QBFField & "], "
strFields = strFields & "[" & rs!QBFField & "], "
End Select
Else
strFields = strFields & "[" & rs!QBFField & "], "
End If
End If
If Not IsNull(rs!Operator) Then
strDelim = rs!Delimiter
strWhere = strWhere & "[" & rs!QBFField & "] " & rs!Operator
Select Case rs!Operator
Case "IN"
strWhere = strWhere & "( " & strDelim & rs!Value1 &
strDelim & ")" & " AND "
Case "Is Null"
strWhere = strWhere & " AND "
Case Else
strWhere = strWhere & strDelim & rs!Value1 & strDelim & "
AND "
End Select


If rs!Operator = "Between" Then
strWhere = strWhere & strDelim & rs!Value2 & strDelim & "
AND "
End If
End If
If Len(rs!SortOrder & "") > 0 Then
If rs!SortOrder <> "N" Then
strOrderBy = strOrderBy & "[" & rs!QBFField & "], "
End If
End If
rs.MoveNext
Next
If Len(strFields) > 2 Then
strFields = left$(strFields, Len(strFields) - 2)
End If
If Len(strWhere) > 5 Then
strWhere = " Where " & left$(strWhere, Len(strWhere) - 4)
End If
If Len(strOrderBy) > 0 Then
strOrderBy = " Order By " & left$(strOrderBy, Len(strOrderBy) - 2)
End If
If Len(strGroupBy) > 0 Then
strGroupBy = " Group By " & left$(strGroupBy, Len(strGroupBy) - 2)
strOrderBy = ""
End If

strSQL = "Select " & strFields & strFrom & strWhere & strGroupBy &
strOrderBy & " ;"
rs.Close
'MsgBox strSQL
strQueryName = "MyQuery"
Set qdUserQuery = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh

DoCmd.OpenForm "frmMyQueryResults", , , , , , strQueryName

cmdReport_Click_Exit:
On Error Resume Next
Exit Sub

cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

End Sub
 
V

Van T. Dinh

* Have you tried Compact & Repair?

* Have you recompiled the code? It sounds like you have compilation errors.

* Have you checked the References Collection and see whether any Refernce is
marked as MISSING? A missing Reference or errors in the References
collection often give the error messages you got.

--
HTH
Van T. Dinh
MVP (Access)



Secret Squirrel said:
Here is the code for that specific function:

Private Sub cmdReport_Click()
On Error GoTo cmdReport_Click_Err
Dim strFields As String
Dim strWhere As String
Dim strFrom As String
Dim strOrderBy As String
Dim strGroupBy As String
Dim booTotals As Boolean
Dim strQueryName As String
Dim qdUserQuery As DAO.QueryDef
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim I As Integer
Dim strSQL As String
Me![sfrmQBFFields].Form.Requery
Set rs = Me![sfrmQBFFields].Form.RecordsetClone
rs.MoveLast
I = rs.RecordCount
rs.MoveFirst

Dim strDelim As String
Set db = DBEngine.Workspaces(0).Databases(0)
strFrom = " From [" & Me![cboSource] & "]"
booTotals = Me.chkTotals = True
For I = 1 To I
If booTotals And rs("qbfTotal") & "" = "" Then
MsgBox "You must select an option in the Total " & _
"column for each field when using Totals.", _
vbInformation + vbOKOnly, "Select All Totals"
Exit Sub
End If
If Not IsNull(rs("QBFField")) Then
If booTotals = True Then
Select Case rs("qbfTotal")
Case "Sum", "Count", "Avg", "Min", "Max"
'rs("qbfTotal") should be one of the above
aggregates
strFields = strFields & rs("qbfTotal") & "([" &
rs!QBFField & _
"]) as [" & rs("qbfTotal") & "_" & rs!QBFField
&
"] , "
Case "Group By"
strGroupBy = strGroupBy & "[" & rs!QBFField & "], "
strFields = strFields & "[" & rs!QBFField & "], "
End Select
Else
strFields = strFields & "[" & rs!QBFField & "], "
End If
End If
If Not IsNull(rs!Operator) Then
strDelim = rs!Delimiter
strWhere = strWhere & "[" & rs!QBFField & "] " & rs!Operator
Select Case rs!Operator
Case "IN"
strWhere = strWhere & "( " & strDelim & rs!Value1 &
strDelim & ")" & " AND "
Case "Is Null"
strWhere = strWhere & " AND "
Case Else
strWhere = strWhere & strDelim & rs!Value1 & strDelim & "
AND "
End Select


If rs!Operator = "Between" Then
strWhere = strWhere & strDelim & rs!Value2 & strDelim & "
AND "
End If
End If
If Len(rs!SortOrder & "") > 0 Then
If rs!SortOrder <> "N" Then
strOrderBy = strOrderBy & "[" & rs!QBFField & "], "
End If
End If
rs.MoveNext
Next
If Len(strFields) > 2 Then
strFields = left$(strFields, Len(strFields) - 2)
End If
If Len(strWhere) > 5 Then
strWhere = " Where " & left$(strWhere, Len(strWhere) - 4)
End If
If Len(strOrderBy) > 0 Then
strOrderBy = " Order By " & left$(strOrderBy, Len(strOrderBy) - 2)
End If
If Len(strGroupBy) > 0 Then
strGroupBy = " Group By " & left$(strGroupBy, Len(strGroupBy) - 2)
strOrderBy = ""
End If

strSQL = "Select " & strFields & strFrom & strWhere & strGroupBy &
strOrderBy & " ;"
rs.Close
'MsgBox strSQL
strQueryName = "MyQuery"
Set qdUserQuery = db.CreateQueryDef(strQueryName, strSQL)
db.QueryDefs.Refresh

DoCmd.OpenForm "frmMyQueryResults", , , , , , strQueryName

cmdReport_Click_Exit:
On Error Resume Next
Exit Sub

cmdReport_Click_Err:
If Err = 3012 Then 'MyQuery wasn't delete from previous usage
db.QueryDefs.Delete "MyQuery"
Resume
Else
MsgBox Err & ": " & Error$, 16, "Error in cmdReport_Click"
Resume cmdReport_Click_Exit:
End If

'Place this just before Exit Sub (or Function)
On Error Resume Next
CurrentDb.QueryDefs("MyQuery").Delete
'Exit Sub, Exit Function, etc.

End Sub
 
V

Van T. Dinh

1. Did you re-compile the code as I mentioned in the previous post?

A possible cause of the first error message you posted is that you have 2 or
more copies of the same sub / function in the same context. If this is the
case, Compile will pick it up.

2. If the above doesn't pick up anything:

* Open the References dialog.
* Note dow the names of some of the References on paper.
* Uncheck to de-select them. Some References can't be deselected so if you
can't, go to another one.
* OK to close the References dialog.
* Open the Refereces dialog (again)
* Re-check the References you unchecked previously. They might have moved
from the top (hence you need to note the names down).
* OK to close the References dialog.
* Re-compile to code again.

The process seems to get rid of some errors in the References collection
that can affect your database.
 
S

Secret Squirrel

I tried to re-compile the code first and that didn't work. Then I tried your
step 2 and that didn't work either.

Do you have any other ideas? Do I maybe have a reference that I shouldn't
have or that maybe conflicts with it? I can't see anything wrong with the
code. I matched it up to the original code that I downloaded. I downloaded
the original database again tonight and the same thing happened with that
one. What could it be?
 
S

Secret Squirrel

It must be on my computer because I just tried it on an older version of my
db on my laptop and it worked fine. Then when I copied the file over to my
desktop I started getting the error code. Where could the problem be on my pc?
 
S

Secret Squirrel

I actually just tried that and it still doesn't work. This problem also
occurs on my pc at work as well. So now I'm thinking there is something else.
Do you think there is something wrong with the references? How do I reinstall
them?
 
V

Van T. Dinh

Probably your Access installation got corrupt. Try repairing your Access /
Office installation.
 
S

Secret Squirrel

Ok I think I figured it out. The version of office I have on this pc is 2003.
I just copied the database over to my laptop which has 2000 on it. And now it
works fine. But my only question is that I have 2000 on my pc at work. I did
notice the references I had were 2003 versions. Could this cause a problem if
I tried to use it with 2000? I reset the references back to the 2000 versions
 
V

Van T. Dinh

Generally, newer Access version recognises References from old version and
change the References to new version. Older Access version may not
recognise References from newer Access version. However, it seems to work
for you.

Copy the working version from your laptop and use it in your office to be
sure.
 
S

Secret Squirrel

Is there anything I can do to make the newer access version recognize the
older references? The older version works because it is using the references
from that version. But when I use the newer version it doesn't work. That
means the newer access version won't recognize the older version references.
That just doesn't make sense why it wouldn't.
 
D

Douglas J. Steele

Depending on what objects you're trying to reference, you should be able to
use Late Binding, and not have to set a reference at all.
 
S

Secret Squirrel

Here are the references I'm using in my db. Not sure what Late Binding is.

Visual Basic for Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft ActiveX Data Objects 2.1 Library
Microsoft DAO 3.6 Object Library
Microsoft Excel 9.0 Object Library

But when I use Access 2003 I have problems with the code I posted earlier in
this thread. Is there an easy way to be able to use 2000 or 2003 with this db?
 
D

Douglas J. Steele

Access should correctly translast the Microsoft Access 9.0 Object Library to
the 11.0 Object Library when you're using Access 2003. What could be causing
problems, though, is your reference to Excel 9.0: if you've got Access 2003,
do you also have Excel 2003?

Tony Toews has a brief introduction to Late Binding at
http://www.granite.ab.ca/access/latebinding.htm
 

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