IF TableExists(strTableName) then MsgBox strTableName & “
found.” else MsgBox strTableName & ” not found.”

Private Function TableExists(TableName) As Boolean
‘I ususally use a global Database object
‘ , however’ you can just as easily pass i
‘ t into the function if you’d prefer
Dim strTableName$ ‘string
On Error GoTo NotFound
If TableName <> “” Then strTableName =
dbMyDatabase.TableDefs(strTableName).Name
‘If the table exists, the string will be
‘ filled, ‘otherwise it will err out and T
‘ ableExists will remain false.
TableExists = True
NotFound:
End Function
‘I have VERY often seen people use the s
‘ tandard routine of
‘going through EACH and EVERY table comp
‘ aring each one till
‘they get the the end, as in

‘For Each MyTable in DB.TableDefs
‘ if MyTable.Name = strNameImLookingFor
‘ then
‘TableExists = true
‘Exit For
‘end if
‘Next
‘This is NOT the way to do this. You will unecesesarily use up yours as well as your users very valuable time.
‘Use this function. Make it private. When you pass the name
‘of the table you need to check for into this routine, the recordset will either retrieve it, with a quickness, or it will error out, which is even quicker.
‘If you have this in a private function, the erroring out will equate to it returning a negative response for the table search.
‘I might add that this technique works superbly with field searches as well (such as Serial No, credit cards, socials, phone numbers, etc).
‘And, there you have it.


Posts anterior y posterior:


Posts Relacionados: