A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Database Design
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Locate a table using VB



 
 
Thread Tools Display Modes
  #1  
Old December 10th, 2009, 06:04 PM posted to microsoft.public.access.tablesdbdesign
Max
external usenet poster
 
Posts: 410
Default Locate a table using VB

I need to find if a given table, MyTableB, exists in the database. Is there a
function, such as IsTable(MyTableB) or Exist(MyTableB) that I can use to make
this determination? I have searched Help and KB with no results.
Please help.
Thanks in advance...
  #3  
Old December 10th, 2009, 09:14 PM posted to microsoft.public.access.tablesdbdesign
Max
external usenet poster
 
Posts: 410
Default Locate a table using VB

Took me a while to find the correct language to use, but here it is:

Dim tdfLoop As TableDef
For Each tdfLoop In CurrentDb().TableDefs
If tdfLoop.Name = "MyTableB" Then
DoCmd.DeleteObject acTable, "MyTableB"
End If
Next tdfLoop

So thanks for the point in the right direction.
Max


"Steve" wrote:

Look at TableDef in the Help file.

Steve



"Max" wrote in message
news
I need to find if a given table, MyTableB, exists in the database. Is there
a
function, such as IsTable(MyTableB) or Exist(MyTableB) that I can use to
make
this determination? I have searched Help and KB with no results.
Please help.
Thanks in advance...



.

  #4  
Old December 10th, 2009, 09:42 PM posted to microsoft.public.access.tablesdbdesign
Steve[_77_]
external usenet poster
 
Posts: 1,017
Default Locate a table using VB

Hi Max,

Way to go!!!

Steve


"Max" wrote in message
...
Took me a while to find the correct language to use, but here it is:

Dim tdfLoop As TableDef
For Each tdfLoop In CurrentDb().TableDefs
If tdfLoop.Name = "MyTableB" Then
DoCmd.DeleteObject acTable, "MyTableB"
End If
Next tdfLoop

So thanks for the point in the right direction.
Max


"Steve" wrote:

Look at TableDef in the Help file.

Steve



"Max" wrote in message
news
I need to find if a given table, MyTableB, exists in the database. Is
there
a
function, such as IsTable(MyTableB) or Exist(MyTableB) that I can use
to
make
this determination? I have searched Help and KB with no results.
Please help.
Thanks in advance...



.



  #5  
Old December 10th, 2009, 09:52 PM posted to microsoft.public.access.tablesdbdesign
Dale Fye
external usenet poster
 
Posts: 2,651
Default Locate a table using VB

Here is a quicker way. All you have to do is refer to the table name and try
to access one of its properties. If it generates an error, you know the
table doesn't exist.

Public Function TableExists(Tablename as string) as boolean

dim dtCreated as date
On error goto ProcError

dtCreated = currentdb.tabledefs(tablename).datecreated

TableExists = true

Exit Sub

ProcError:
if err.number = 3265 then 'item not found in collection
TableExists = false
else
msgbox "Error encountered in TableExists function"
TableExists = false
endif

End function

Then use:

Public Sub DeleteIfExists(Tablename as string)

if TableExists(tablename) then
docmd.deleteobject actable, tablename
endif

End sub

----
HTH
Dale



"Max" wrote:

Took me a while to find the correct language to use, but here it is:

Dim tdfLoop As TableDef
For Each tdfLoop In CurrentDb().TableDefs
If tdfLoop.Name = "MyTableB" Then
DoCmd.DeleteObject acTable, "MyTableB"
End If
Next tdfLoop

So thanks for the point in the right direction.
Max


"Steve" wrote:

Look at TableDef in the Help file.

Steve



"Max" wrote in message
news
I need to find if a given table, MyTableB, exists in the database. Is there
a
function, such as IsTable(MyTableB) or Exist(MyTableB) that I can use to
make
this determination? I have searched Help and KB with no results.
Please help.
Thanks in advance...



.

 




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 Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:48 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.