I have a problem with the following code. The code bombs out at the Set rst = qdf.OpenRecordset(dbOpenSnapshot) line. The code does not go any futher than that line and goes to the ProcessQuery_ErrorHandler even though all fields and tables are selected. This code works fine in Access 2003. What am I missing? Here is the code:
Public Sub cmdProcessQuery_Click()
On Error GoTo ProcessQuery_ErrorHandler
DoCmd.Close acQuery, "Sampquer", acSaveNo
Dim strsql As String, dbs As Database, qdf As QueryDef, rst As Recordset
Set dbs = CurrentDb()
dbs.QueryDefs.Refresh
For Each qdf In dbs.QueryDefs
If qdf.Name = "Sampquer" Then
DoCmd.DeleteObject acQuery, "Sampquer"
End If
Next qdf
Set qdf = dbs.CreateQueryDef("Sampquer")
BuildSQLString strsql
qdf.SQL = strsql
' Set rst = qdf.OpenRecordset(dbOpenSnapshot, dbDenyWrite)
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
DoCmd.OpenQuery "Sampquer"
lblQueryHelp.Visible = False
chkGroupBy.Enabled = True
chkSumQuantity.Enabled = True
chkSumTotalGiveUpAmount.Enabled = True
Exit_Procedure:
Exit Sub
ProcessQuery_ErrorHandler:
MsgBox "There is a problem with your Query. You may not have selected any fields or not selected a table. You may have used an Or with an Is Between in one of your query lines. Please check your query over."
Resume Exit_Procedure
End Sub
Public Sub cmdProcessQuery_Click()
On Error GoTo ProcessQuery_ErrorHandler
DoCmd.Close acQuery, "Sampquer", acSaveNo
Dim strsql As String, dbs As Database, qdf As QueryDef, rst As Recordset
Set dbs = CurrentDb()
dbs.QueryDefs.Refresh
For Each qdf In dbs.QueryDefs
If qdf.Name = "Sampquer" Then
DoCmd.DeleteObject acQuery, "Sampquer"
End If
Next qdf
Set qdf = dbs.CreateQueryDef("Sampquer")
BuildSQLString strsql
qdf.SQL = strsql
' Set rst = qdf.OpenRecordset(dbOpenSnapshot, dbDenyWrite)
Set rst = qdf.OpenRecordset(dbOpenSnapshot)
DoCmd.OpenQuery "Sampquer"
lblQueryHelp.Visible = False
chkGroupBy.Enabled = True
chkSumQuantity.Enabled = True
chkSumTotalGiveUpAmount.Enabled = True
Exit_Procedure:
Exit Sub
ProcessQuery_ErrorHandler:
MsgBox "There is a problem with your Query. You may not have selected any fields or not selected a table. You may have used an Or with an Is Between in one of your query lines. Please check your query over."
Resume Exit_Procedure
End Sub