Message 1 of 7
DbxDocs in collection all return same name

Not applicable
05-11-2009
08:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
This is puzzling me
'in a class containing dbx functionality...
Private moDbxDoc as axdbDocument
'in Init method...create dbxdoc via GetInterface
I have a collection of filenames
I open each in turn via dbx
For Each vFile In mColFileNames
FileName = CStr(vFile)
modbxdoc.Open Filename
I add each opened doc to collection
colDocs.Add moDbxDoc, moDbxDoc.Name
...then after processing...
I close each doc in collection, returning it's name for confirmation
Dim oDoc As AxDbDocument
For Each oDoc In colDocs
LogEntry "Close ", oDoc.Name
Set oDoc = Nothing'
Next
Set colDocs = Nothing
>>> They all return the same name (of the last file in the list) <<<
any one can explain this?
I'm assuming it's something to do with re-using the member variable moDbxDoc
to open each doc in turn
but don't understand why putting them in collection doesn't retain their
identity, but sets them all to the same one
do I need to create a local variable for each doc to keep them separate?
I used to recreate the interface for each file to be opened but thought if I
kept the docs in a collection I could create one interface and reuse it for
multiple files instead of recreating the interface multiple times
(like creating multiple database connections versus re-using one connection)
Thanks for any input
Mark
This is puzzling me
'in a class containing dbx functionality...
Private moDbxDoc as axdbDocument
'in Init method...create dbxdoc via GetInterface
I have a collection of filenames
I open each in turn via dbx
For Each vFile In mColFileNames
FileName = CStr(vFile)
modbxdoc.Open Filename
I add each opened doc to collection
colDocs.Add moDbxDoc, moDbxDoc.Name
...then after processing...
I close each doc in collection, returning it's name for confirmation
Dim oDoc As AxDbDocument
For Each oDoc In colDocs
LogEntry "Close ", oDoc.Name
Set oDoc = Nothing'
Next
Set colDocs = Nothing
>>> They all return the same name (of the last file in the list) <<<
any one can explain this?
I'm assuming it's something to do with re-using the member variable moDbxDoc
to open each doc in turn
but don't understand why putting them in collection doesn't retain their
identity, but sets them all to the same one
do I need to create a local variable for each doc to keep them separate?
I used to recreate the interface for each file to be opened but thought if I
kept the docs in a collection I could create one interface and reuse it for
multiple files instead of recreating the interface multiple times
(like creating multiple database connections versus re-using one connection)
Thanks for any input
Mark