473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Delete Table

Hello!

I wanna import a table with a makro, but a table with this name already
exists. So the imported table (f. i. "table") is saved as "table1". How can
I check, if such a table already exists and then delete it?
So how can I check the existence of a table?

________________________________________
Function Importieren1()
On Error GoTo Importieren1_Err

DoCmd.DeleteObject acTable, "schueler"
DoCmd.RunCommand acCmdImport
Importieren1_Exit:
Exit Function

Importieren1_Err:
MsgBox Error$
Resume Importieren1_Exit

End Function
________________________________________

Yours Jürgen
Nov 12 '05 #1
3 5881
pw
>Hello!

I wanna import a table with a makro, but a table with this name already
exists. So the imported table (f. i. "table") is saved as "table1". How can
I check, if such a table already exists and then delete it?
So how can I check the existence of a table?

________________________________________
Function Importieren1()
On Error GoTo Importieren1_Err

DoCmd.DeleteObject acTable, "schueler"
DoCmd.RunCommand acCmdImport
Importieren1_Exit:
Exit Function

Importieren1_Err:
MsgBox Error$
Resume Importieren1_Exit

End Function
________________________________________

Yours Jürgen


Not sure how to check if a table exists, but you can use the DROP
command (check the help file) to delete an Access table:

dbCurrDb.Execute "DROP TABLE tblResCloneWrkf;"
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 12 '05 #2
Hi Micheal,

This is from the Microsoft Knowledge Base:
Copy and paste this code into a new module (in the database window)

-----------------------------------------------------

'INF: How to Determine If a Table or Query Exists
'Article id: Q113549
'Copyright (c) Microsoft Corporation. All rights reserved.
'************************************************* *******
' FUNCTION: IsTableQuery()
'
' PURPOSE: Determine if a table or query exists.
'
' ARGUMENTS:
' DbName: The name of the database. If the database name
' is "" the current database is used.
' TName: The name of a table or query.
'
' RETURNS: True (it exists) or False (it does not exist).
'
'************************************************* *******

Function IsTableQuery(DbName As String, TName As String) As Integer
Dim Db As Database, Found As Integer, Test As String
Const NAME_NOT_IN_COLLECTION = 3265

' Assume the table or query does not exist.
Found = False

' Trap for any errors.
On Error Resume Next

' If the database name is empty...
If Trim$(DbName) = "" Then
' ...then set Db to the current Db.
Set Db = CurrentDb()

Else
' Otherwise, set Db to the specified open database.
Set Db = DBEngine.Workspaces(0).OpenDatabase(DbName)

' See if an error occurred.
If Err Then
MsgBox "Could not find database to open: " & DbName
IsTableQuery = False
Exit Function
End If
End If

' See if the name is in the Tables collection.
Test = Db.TableDefs(TName).Name

If Err <> NAME_NOT_IN_COLLECTION Then Found = True

' Reset the error variable.
Err = 0

' See if the name is in the Queries collection.
Test = Db.QueryDefs(TName$).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True

Db.Close

IsTableQuery = Found

End Function
-----------------------------------------------------
Then use it like this:
If IsTableQuery("", "schueler") Then
DoCmd.DeleteObject acTable, "schueler"
End If

*******************************************
HTH,
Don
Michael Magg <ao***********@aon.at> wrote in message
news:40***********************@newsreader02.highwa y.telekom.at...
Hello!

I wanna import a table with a makro, but a table with this name already
exists. So the imported table (f. i. "table") is saved as "table1". How can I check, if such a table already exists and then delete it?
So how can I check the existence of a table?

________________________________________
Function Importieren1()
On Error GoTo Importieren1_Err

DoCmd.DeleteObject acTable, "schueler"
DoCmd.RunCommand acCmdImport
Importieren1_Exit:
Exit Function

Importieren1_Err:
MsgBox Error$
Resume Importieren1_Exit

End Function
________________________________________

Yours Jürgen

Nov 12 '05 #3
"Don Leverton" <My*****@Telus.Net> wrote in news:42fmc.2612$uN4.305
@clgrps12:
Hi Micheal,

This is from the Microsoft Knowledge Base:
Copy and paste this code into a new module (in the database window)
I'm sure it was a full chapter in War and Peace before that!

-----------------------------------------------------

'INF: How to Determine If a Table or Query Exists
'Article id: Q113549
'Copyright (c) Microsoft Corporation. All rights reserved.
'************************************************* *******
' FUNCTION: IsTableQuery()
'
' PURPOSE: Determine if a table or query exists.
'
' ARGUMENTS:
' DbName: The name of the database. If the database name
' is "" the current database is used.
' TName: The name of a table or query.
'
' RETURNS: True (it exists) or False (it does not exist).
'
'************************************************* *******

Function IsTableQuery(DbName As String, TName As String) As Integer
Dim Db As Database, Found As Integer, Test As String
Const NAME_NOT_IN_COLLECTION = 3265

' Assume the table or query does not exist.
Found = False

' Trap for any errors.
On Error Resume Next

' If the database name is empty...
If Trim$(DbName) = "" Then
' ...then set Db to the current Db.
Set Db = CurrentDb()

Else
' Otherwise, set Db to the specified open database.
Set Db = DBEngine.Workspaces(0).OpenDatabase(DbName)

' See if an error occurred.
If Err Then
MsgBox "Could not find database to open: " & DbName
IsTableQuery = False
Exit Function
End If
End If

' See if the name is in the Tables collection.
Test = Db.TableDefs(TName).Name

If Err <> NAME_NOT_IN_COLLECTION Then Found = True

' Reset the error variable.
Err = 0

' See if the name is in the Queries collection.
Test = Db.QueryDefs(TName$).Name
If Err <> NAME_NOT_IN_COLLECTION Then Found = True

Db.Close

IsTableQuery = Found

End Function
-----------------------------------------------------
Then use it like this:
If IsTableQuery("", "schueler") Then
DoCmd.DeleteObject acTable, "schueler"
End If

*******************************************
HTH,
Don
Michael Magg <ao***********@aon.at> wrote in message
news:40***********************@newsreader02.highwa y.telekom.at...
Hello!

I wanna import a table with a makro, but a table with this name already
exists. So the imported table (f. i. "table") is saved as "table1". How

can
I check, if such a table already exists and then delete it?
So how can I check the existence of a table?

________________________________________
Function Importieren1()
On Error GoTo Importieren1_Err

DoCmd.DeleteObject acTable, "schueler"
DoCmd.RunCommand acCmdImport
Importieren1_Exit:
Exit Function

Importieren1_Err:
MsgBox Error$
Resume Importieren1_Exit

End Function
________________________________________

Yours Jürgen



--
Lyle
(for e-mail refer to http://ffdba.com/contacts.htm)
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Andrew DeFaria | last post by:
I created the following .sql file to demonstrate a problem I'm having. According to the manual: If |ON DELETE CASCADE| is specified, and a row in the parent table is deleted, then InnoDB...
2
by: Bob Ganger | last post by:
Hello, I am working on a project using SQL Server 2000 with a database containing about 10 related tables with a lot of columns containing text. The total current size of the database is about...
16
by: robert | last post by:
been ruminating on the question (mostly in a 390/v7 context) of whether, and if so when, a row update becomes an insert/delete. i assume that there is a threshold on the number of columns of the...
8
by: John Baker | last post by:
Hi: Access 2000 W98! I have a table with numerous records in it, and am attempting to delete certain records that have been selected from it. These are selected based on the ID number in a...
3
by: John Rivers | last post by:
Hello, I think this will apply to alot of web applications: users want the ability to delete a record in table x this record is related to records in other tables and those to others in...
9
by: Dejan | last post by:
Hy, Sorry for my terreble english I have this simple code for deleting rows in mysql table... Everything works fine with it. So, what do i wanna do...: my sql table looks something like...
6
by: polocar | last post by:
Hi, I'm writing a program in Visual C# 2005 Professional Edition. This program connects to a SQL Server 2005 database called "Generations" (in which there is only one table, called...
3
by: bluez | last post by:
I want to design a webpage where user can search the data from the database and list out the related records. Each of the record got a delete button which allow user to delete the record. ...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
On a form - I have a datagridview which is docked to the entire form. The datagridview allows users to Delete and/or Add Rows. On the Form_Load event I Fill the datagridview source table with a...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.