dbTalk Databases Forums  

Word path from access - network

comp.databases.ms-access comp.databases.ms-access


Discuss Word path from access - network in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Word path from access - network - 01-16-2011 , 04:02 PM






Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:m-mdnTPmHOAiRazQnZ2dnUVZ_sqdnZ2d (AT) earthlink (DOT) com:

Quote:
Any idea why this code fails?
Dim t As TableDef
Dim s as string
Set t = CurrentDb.TableDefs("SomeTableName")
s = Mid(t.Connect, 11) 'gets the backend file name

It says Object invalid is not longer set.
Because the object CurrentDB returned is no longer there, so its
child objects are also not accessible.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #12  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Word path from access - network - 01-16-2011 , 04:03 PM






Salad <salad (AT) oilandvinegar (DOT) com> wrote in
news:JZidnW-j37s7bKzQnZ2dnUVZ_sSdnZ2d (AT) earthlink (DOT) com:

Quote:
If I add a
Dim d as database
set d = currentdb
and modify the Set t line to
Set t = d.tabledefs("SomeTableName")
it works.

Yet if works fine using David's code which was
s = Mid(CurrentDB.TableDefs(strTableName).Connect, 11)
This last works because the object returned by CurrentDB is used
immediately to find information about child ojbects.

The previous works because you cache the object returned.

The one the breaks does not use the object returned by CurrentDB
immediately and does not cache it, so it its child objects are not
accessible (because it no longer exists).

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
  #13  
Old   
David-W-Fenton
 
Posts: n/a

Default Re: Word path from access - network - 01-16-2011 , 04:07 PM



"Bob Barrows" <reb01501 (AT) NOSPAMyahoo (DOT) com> wrote in
news:igsubr$ckr$1 (AT) news (DOT) eternal-september.org:

Quote:
Let me see if I can reproduce that in A2007 ... yes, I can easily
reproduce it. Now that I went through the exercise, I do vaguley
remember this issue but I no longer remember why it doesn't work.
Something about the implicit database variable returned by
CurrentDB in memory going out of scope as soon as the statement
finishes executing. Change it to

Dim t As TableDef
Dim s As String
Set t = DBEngine(0)(0).TableDefs("tblinvoices")
s = Mid(t.Connect, 11) 'gets the backend file name

and it works fine
DBEngine(0)(0) returns the same thing every time, a reference to the
first item of the database collection in the default workspace. This
is almost always the database open in the Access UI (though during
the running of a wizard, it could return a reference to the wizard,
but it's very hard to use DBEngine(0)(0) while a wizard is running,
of course...).

That's completely different from what CurrentDB returns. While
DBEngine(0)(0) returns a pointer to the exact same object eery time
you call it, CurrentDB returns a completely different object each
time you call it. It's not a pointer to the same object, but a
pointer to a newly created memory structure that points back to the
database open in the Access UI. It's because of this fact that you
can't use the object returned by CurrentDB (or its children) in
anotherline of code unless you've cached that object.

You *can* use DBEngine(0)(0), because it's returning the same thing
every time, and that's why the code above works just fine where as
doing the same thing with CurrentDB does not.

--
David W. Fenton http://www.dfenton.com/
contact via website only http://www.dfenton.com/DFA/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.