Access97: TableDef not returnable???

  • Thread starter Thread starter Jonathan Scott via AccessMonster.com
  • Start date Start date
J

Jonathan Scott via AccessMonster.com

I have a function that is supposed to return a tabledef. Inside that
function "getTable()", I am able to print out the name of the table,
however when I come out of the function, the caller's reference still seems
to be un-assigned.

Here is the code:

Set actualTable = getTable(databaseFilename, ACTUALTABLENAME)
Set importTable = getTable(databaseFilename, Me!oldTableList)
MsgBox "Actual = '" & actualTable.Name & "'"
MsgBox "Import = '" & importTable.Name & "'"

Public Function getTable(databaseFilename As String, tableName As String)
As tableDef
Dim tables As TableDefs
Dim thisTable As tableDef
Set tables = getTableList(databaseFilename)

Set thisTable = tables(tableName)
Set getTable = thisTable
MsgBox "'" & getTable.Name & "'"
Exit Function
End Function

Both tries to print the name of the table from the caller result in the
error "Object is invalid or has not been set" (or something similar, as
it's in Japanese).

Any help would be appreciated. Perhaps I just need to try again after
having my first coffee of the morning?

Jonathan Scott
 
At a guess, the getTableList() function is creating a Database object in
order to retrieve and deliver the TableDefs object, the same Database
object is being (implictly) used by getTable() - but it is out of scope
by the time you get to the function that called getTable().

What happens if you declare a module-level database object and have
getTableList use that?
 
John,

Thank you for the reply. I found that if I open the database in the caller
and hand it to the function, it comes back intact. I forgot that Access
asynchronously destroys objects and re-assigns values. Would be nice to
know that when you have a reference to an object that it will be there
until you stop referencing it. (wishful thinking)

Jonathan Scott
 
Back
Top