私はこのサンプルコードを手に入れました:
<!-- language: lang-vb -->
Option Compare Database
Private Function get_relation() As String
get_relation = CurrentDb.Relations(1).name
Debug.Print "Inside get_relation() relation name is " & get_relation
' Inside get_relation() relation name is Table1Table2
Debug.Print "Again, the name is " & CurrentDb.Relations(get_relation).name
' Again, the name is Table1Table2
End Function
Public Sub test()
Dim R As DAO.Relation, name As String
name = get_relation()
Debug.Print "Outside, the name is still " & name
' Outside, the name is still Table1Table2
Set R = CurrentDb.Relations(name)
Debug.Print "Again, the name is " & R.name
' At the line above it throws error!
End Sub
出力は次のとおりです。
Inside get_relation() relation name is Table1Table2
Again, the name is Table1Table2
Outside, the name is still Table1Table2
次に、エラーがあります。
Runtime error '3420':
Object invalid or no longer set.
これは私が時計で見るものです:
Watch : : Name : "Table1Table2" : String : Playground.test
Watch : - : CurrentDb.Relations(Name) : : Object/Relation : Playground.test
: Attributes : <Object invalid or no longer set.> : Long : Playground.test
: Fields : <Object invalid or no longer set.> : Fields : Playground.test
: ForeignTable : <Object invalid or no longer set.> : String : Playground.test
: Name : <Object invalid or no longer set.> : String : Playground.test
: PartialReplica : <Object invalid or no longer set.> : Boolean : Playground.test
: Properties : <Object invalid or no longer set.> : Properties : Playground.test
: Table : <Object invalid or no longer set.> : String : Playground.test
Watch : - : R : : Relation/Relation : Playground.test
: Attributes : <Object invalid or no longer set.> : Long : Playground.test
: Fields : <Object invalid or no longer set.> : Fields : Playground.test
: ForeignTable : <Object invalid or no longer set.> : String : Playground.test
: Name : <Object invalid or no longer set.> : String : Playground.test
: PartialReplica : <Object invalid or no longer set.> : Boolean : Playground.test
: Properties : <Object invalid or no longer set.> : Properties : Playground.test
: Table : <Object invalid or no longer set.> : String : Playground.test
したがって、ある時点で、私のDAO.Relation Rが設定解除されます(または、少なくともそのメンバーすべてが設定解除されます)。さらに多くのCurrentDB.Relations( "Table1Table2")とCurrentDB.Relations(1)が同じ状態になっています(すべてのメンバーが無効または設定されていません)。
同時に、ウォッチを介して検査されたCurrentDB.Relationsは、すべてのメンバーが設定されていることを示しており、すべてが正常であるように見えます。
私の質問はあまり具体的ではないことは知っていますが、実際にはわかりません。ヒントはありますか?