B
Bill
In the code segment below, I get an Run-time
error '91' the first time I make a reference to the
fields collection of the TableDefs object variable
tbfInstProp when the reference is not within the
current sub.
(Err91: Object variable or With block variable not set)
That is, if I move the code you see at the beginning
of sub InitVer7pt1 immediately after:
Set tdfInstProp = dbTMS.TableDefs("InstProperties")
Then that code runs as expected, looping through the
fields collection of the TableDef.
I guess the question is how come the scope of
tblInstProp doesn't extend to subs within the general
module?
===============================================
Option Compare Database
Option Explicit
Dim dbTMS As DAO.Database 'Object variable for our database
Dim rsInstProp As DAO.Recordset 'Object variable for our DAO recordset
Dim fldName As DAO.Field 'Ojbect variable for members of the field
collection
Dim tdfInstProp As DAO.TableDef 'Object variable for InstProperties table
definition
Dim stSQL As String 'Working string for our SQL queries
Dim booNotFound As Boolean
Public Sub DAO_Example()
IPDatabase = DLookup("InstDatabase", "InstProperties") 'Fetch name TMS
backend DB
Set dbTMS = OpenDatabase(IPDatabase) 'Ok. Open backend DB
Set rsInstProp = dbTMS.OpenRecordset("InstProperties") 'Default is Dynaset
Set tdfInstProp = dbTMS.TableDefs("InstProperties") 'Need to look at
InstProp tbldefs
Call InitVer7pt1 '7.1 is the 1st version of field upgradable mdb's.
..
..
..
..
..
Set tdfInstProp = Nothing
'Close the properties table recordset.
rsInstProp.Close 'Close the recordset
Set rsInstProp = Nothing 'Free up its memory
dbTMS.Close 'Close TMS backend DB
Set dbTMS = Nothing 'Free up its memory
If IPDBVersion < TMSDBVersion Then Call Upgrade
End Sub
----------------------------------------------------------------
Private Sub InitVer7pt1()
booNotFound = True
For Each fldName In tdfInstProp.Fields 'For each field in the
fields collection
If fldName.Name = "InstDBVersion" Then 'This the field we're
looking for?
booNotFound = False 'YES, set
not-found-indicator to false
Exit For 'We're done searching the
collection
End If
Next fldName 'NO, step to next field
..
..
..
..
===============================================
error '91' the first time I make a reference to the
fields collection of the TableDefs object variable
tbfInstProp when the reference is not within the
current sub.
(Err91: Object variable or With block variable not set)
That is, if I move the code you see at the beginning
of sub InitVer7pt1 immediately after:
Set tdfInstProp = dbTMS.TableDefs("InstProperties")
Then that code runs as expected, looping through the
fields collection of the TableDef.
I guess the question is how come the scope of
tblInstProp doesn't extend to subs within the general
module?
===============================================
Option Compare Database
Option Explicit
Dim dbTMS As DAO.Database 'Object variable for our database
Dim rsInstProp As DAO.Recordset 'Object variable for our DAO recordset
Dim fldName As DAO.Field 'Ojbect variable for members of the field
collection
Dim tdfInstProp As DAO.TableDef 'Object variable for InstProperties table
definition
Dim stSQL As String 'Working string for our SQL queries
Dim booNotFound As Boolean
Public Sub DAO_Example()
IPDatabase = DLookup("InstDatabase", "InstProperties") 'Fetch name TMS
backend DB
Set dbTMS = OpenDatabase(IPDatabase) 'Ok. Open backend DB
Set rsInstProp = dbTMS.OpenRecordset("InstProperties") 'Default is Dynaset
Set tdfInstProp = dbTMS.TableDefs("InstProperties") 'Need to look at
InstProp tbldefs
Call InitVer7pt1 '7.1 is the 1st version of field upgradable mdb's.
..
..
..
..
..
Set tdfInstProp = Nothing
'Close the properties table recordset.
rsInstProp.Close 'Close the recordset
Set rsInstProp = Nothing 'Free up its memory
dbTMS.Close 'Close TMS backend DB
Set dbTMS = Nothing 'Free up its memory
If IPDBVersion < TMSDBVersion Then Call Upgrade
End Sub
----------------------------------------------------------------
Private Sub InitVer7pt1()
booNotFound = True
For Each fldName In tdfInstProp.Fields 'For each field in the
fields collection
If fldName.Name = "InstDBVersion" Then 'This the field we're
looking for?
booNotFound = False 'YES, set
not-found-indicator to false
Exit For 'We're done searching the
collection
End If
Next fldName 'NO, step to next field
..
..
..
..
===============================================