Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem converting to Access 2007 VBA with Recordset 1

Status
Not open for further replies.

hedgracer

Programmer
Mar 21, 2001
186
US
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
 
Replace this:
rst As Recordset
with this:
rst As DAO.Recordset

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top