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  

Checking for Table Existence before deleting



 
 
Thread Tools Display Modes
  #1  
Old March 22nd, 2005, 09:17 PM
Joey
external usenet poster
 
Posts: n/a
Default Checking for Table Existence before deleting

Hello All,

I would like to check to see if a table exists first before deleting it
(to avoid an error). How would I do this? It seems like this should be
an easy task.

Thanks,
Joey.
  #2  
Old March 23rd, 2005, 12:04 AM
John Vinson
external usenet poster
 
Posts: n/a
Default

On Tue, 22 Mar 2005 21:17:58 GMT, Joey "jpk808[NO
wrote:

Hello All,

I would like to check to see if a table exists first before deleting it
(to avoid an error). How would I do this? It seems like this should be
an easy task.

Thanks,
Joey.


It's easiest to simply use error trapping to detect the error, and
either issue a message friendlier than the Access default or simply
Resume Next.

John W. Vinson[MVP]
  #3  
Old March 23rd, 2005, 12:29 AM
Jeff Conrad
external usenet poster
 
Posts: n/a
Default

Public Function funcTableExists(strTable As String) As Boolean
On Error GoTo ErrorPoint

' This function will check to see if a
' table exists within the current database
' Similar to IsLoaded function it will return True or False
' Jeff Conrad - Access Junkie

Dim db As DAO.Database
Dim doc As DAO.Document

Set db = CurrentDb()

With db.Containers!Tables
For Each doc In .Documents
If doc.Name = strTable Then
funcTableExists = True
End If
Next doc
End With

ExitPoint:
On Error Resume Next
Set db = Nothing
Exit Function

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Function

--
Jeff Conrad
Access Junkie
Bend, Oregon

"Joey" "jpk808[NO wrote in message
news:aY%%d.759931$8l.288619@pd7tw1no...

Hello All,

I would like to check to see if a table exists first before deleting it
(to avoid an error). How would I do this? It seems like this should be
an easy task.

Thanks,
Joey.



  #4  
Old March 23rd, 2005, 04:36 PM
Rudi
external usenet poster
 
Posts: n/a
Default

Hi,

I had a similar question and solved it like this :

Perform a command on the table and trap the error that comes when
table doesn't exist.

For instance : VarDummy=dcount("[field1]";"Table1")

If the table doesn't exist, a trapable error occurs.

This seems workable to me.....(Hope I'm right)

Regards,
Rudi.
 




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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting a Key barry General Discussion 0 January 27th, 2005 01:07 AM
deleting red outlined formatting marks without deleting formatted Goldtag Page Layout 0 November 19th, 2004 03:55 AM
Deleting links without deleting the table. Calaska Database Design 2 October 21st, 2004 10:33 PM


All times are GMT +1. The time now is 12:42 AM.


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