error 13 on openrecordset

  • Thread starter Thread starter Tom Hanley
  • Start date Start date
T

Tom Hanley

Access 2003, Win XP Pro
here's a sub in my main module that gives error 13 when executed during on current event in form. any ideas?


Sub TEST_STABILIZED(TEST_STABILIZED_PNO)

Dim MyWorkspace As Workspace
Dim MyDatabase As Database
Dim myset As Recordset
Dim MyFile As String
Dim ErrorCondition As Integer
Dim Criteria, X As String

Set MyWorkspace = DBEngine.Workspaces(0) 'printing this in immediate window gives error 13
Set MyDatabase = MyWorkspace.Databases(0) 'printing this in immediate window gives error 13

'----- test for bof
X = "SELECT SOILTEST.* FROM SOILTEST WHERE (((SOILTEST.PNO)>=8001) AND ((SOILTEST.PNO)<=8999));"
Set myset = MyDatabase.OpenRecordset(X, dbOpenDynaset) 'error 13 at this line
If myset.RecordCount < 1 Then
BOF_FLAG = True
Else
BOF_FLAG = False
End If
'----- end test for bof

X = "SELECT PERCDATA.PNO, PERCDATA.START_TIME, PERCDATA.END_TIME FROM PERCDATA WHERE PERCDATA.PNO = " & TEST_STABILIZED_PNO & " ORDER BY PERCDATA.START_TIME;"
Set myset = MyDatabase.OpenRecordset(X, DB_OPEN_DYNASET)

Dim RATE1, RATE2 As Single
Dim START_TIME1, END_TIME1, START_TIME2, END_TIME2 As Date

STABILIZED_FLAG = ""
perc_rate_calc = "N/G"
passed_flag = False


End Sub
 
Not sure what you mean by "printing this in immediate window gives error
13", but try changing your declaration from

Dim myset As Recordset

to

Dim myset As DAO.Recordset

In Access 2003, ADO has a higher position in the list of default references
than DAO. When you don't disambiguate like the above, Access is going to
pick the first Recordset object it comes to, which will be the ADO
Recordset.

BTW, others of your declarations are probably not doing what you expect. For
example,

Dim Criteria, X As String

is declaring X as a String, but Criteria as Variant. That's because VBA
doesn't allow short-circuiting of declarations. If you want them both to be
strings, you need:

Dim Criteria As String, X As String

Same issue with your declarations of

Dim RATE1, RATE2 As Single
Dim START_TIME1, END_TIME1, START_TIME2, END_TIME2 As Date


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Access 2003, Win XP Pro
here's a sub in my main module that gives error 13 when executed during on
current event in form. any ideas?


Sub TEST_STABILIZED(TEST_STABILIZED_PNO)

Dim MyWorkspace As Workspace
Dim MyDatabase As Database
Dim myset As Recordset
Dim MyFile As String
Dim ErrorCondition As Integer
Dim Criteria, X As String

Set MyWorkspace = DBEngine.Workspaces(0) 'printing this in immediate window
gives error 13
Set MyDatabase = MyWorkspace.Databases(0) 'printing this in immediate window
gives error 13

'----- test for bof
X = "SELECT SOILTEST.* FROM SOILTEST WHERE (((SOILTEST.PNO)>=8001) AND
((SOILTEST.PNO)<=8999));"
Set myset = MyDatabase.OpenRecordset(X, dbOpenDynaset) 'error 13 at this
line
If myset.RecordCount < 1 Then
BOF_FLAG = True
Else
BOF_FLAG = False
End If
'----- end test for bof

X = "SELECT PERCDATA.PNO, PERCDATA.START_TIME, PERCDATA.END_TIME FROM
PERCDATA WHERE PERCDATA.PNO = " & TEST_STABILIZED_PNO & " ORDER BY
PERCDATA.START_TIME;"
Set myset = MyDatabase.OpenRecordset(X, DB_OPEN_DYNASET)

Dim RATE1, RATE2 As Single
Dim START_TIME1, END_TIME1, START_TIME2, END_TIME2 As Date

STABILIZED_FLAG = ""
perc_rate_calc = "N/G"
passed_flag = False


End Sub
 
That solved my Error problem...thanks!
Now I hope it won't be a different issue when I save this back to access 97
format so it'll work within AutoCAD as an XDRef database. UUUUGGGGGHHHH!!!!!
 
Back
Top