LadyMarmalade
Registered User.
- Local time
- Today, 04:03
- Joined
- Sep 23, 2014
- Messages
- 26
Hi guys,
I have a function which is intended to return a TableDef
I have two issues:
Thank you!
Lady Marmalade
I have a function which is intended to return a TableDef
Code:
Function GetTable(ByVal TableCode As String) As TableDef
Dim myTable As DAO.TableDef
Dim myDB As DAO.Database
Set myDB = CurrentDb
For Each myTable In myDB.TableDefs
If myTable.Name Like TableCode & "*" Then
Set GetTable = myTable
Set myDB = Nothing
Exit Function
End If
Next myTable
NoneFound:
MsgBox ("No table with code " & TableCode & " found.")
Set myDB = Nothing
End Function
I have two issues:
- Run-time error '3420'
It gets as far as finding the table before returning "Object invalid or no longer set"
I have tried replacing Set GetTable = myTable to Set GetTable = myDB.TableDefs(myTable.Name) - no luck. - Returning an error if unfound
Is there a better way to do this? If I later do something like GetTable("C5").Name I expect it'd not be happy with GetTable not being defined.
Thank you!
Lady Marmalade