473,495 Members | 2,058 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Macro Conditions - Check if table name exists

10 New Member
what should be the syntax of a macro condition if I want to check if the table name is already existing? I need this condition so that if the table name is existing, the macro will perform other task and avoid getting an error. For example, I have Table1 already and I run the macro w/o the condition, it will result to an error. I need the condition to skip actions that will produce the error.
any idea will help. thanks in advance!
Dec 18 '06 #1
7 14057
Tanis
143 New Member
Try this function. I would try to steer clear of macros. Use them only when you have to.

Expand|Select|Wrap|Line Numbers
  1. Function TableExists(strTableName As String) As Integer
  2. 'Returns True if table exists
  3. Dim dbs As Database
  4. Dim i As Integer
  5. Set dbs = CurrentDb()
  6. TableExists = False
  7. dbs.TableDefs.Refresh
  8. For i = 0 To dbs.TableDefs.Count - 1
  9. If strTableName = dbs.TableDefs(i).Name Then
  10. 'Table Exists
  11. TableExists = True
  12. Exit For
  13. End If
  14. Next i
  15. DoCmd.DeleteObject acTable, strTableName
  16.  
  17. Set dbs = Nothing
  18. End Function
  19.  
Dec 18 '06 #2
NeoPa
32,556 Recognized Expert Moderator MVP
Tanis makes a good point.
Try this slightly shorter/more straightforward function though.
Expand|Select|Wrap|Line Numbers
  1. Public Function TableExists(strTable As String) As Boolean
  2.     Dim strName As String
  3.  
  4.     On Error Resume Next
  5.     'If table exists already then strName will be > ""
  6.     strName = CurrentDb.TableDefs(strTable).Name
  7.     TableExists = Not (strName = "")
  8. End Function
Dec 19 '06 #3
rytsyd
10 New Member
sad to say but I really have to do it using macro =(
Dec 20 '06 #4
rytsyd
10 New Member
still needs help in macro conditions...thanks!
Dec 21 '06 #5
MMcCarthy
14,534 Recognized Expert Moderator MVP
what should be the syntax of a macro condition if I want to check if the table name is already existing? I need this condition so that if the table name is existing, the macro will perform other task and avoid getting an error. For example, I have Table1 already and I run the macro w/o the condition, it will result to an error. I need the condition to skip actions that will produce the error.
any idea will help. thanks in advance!
I honestly don't know of a way to do this using a macro. One of the reasons VBA was designed is because macros are limited.

Mary
Dec 21 '06 #6
rytsyd
10 New Member
ok...thanks mary!
Dec 21 '06 #7
MMcCarthy
14,534 Recognized Expert Moderator MVP
ok...thanks mary!
Wish I could have helped more. If you decide you want to try VBA let us know and we'll do what we can to help.

Mary
Dec 21 '06 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
13376
by: steve lord | last post by:
Greetings all, I have a macro that should add a column to a table if the column doesn't already exist. Using the macro condition, how can I test for whether a specific column name in a specific...
1
4462
by: Jo | last post by:
I am having a real problem with the Launch conditions in VS .NET and can only come to the conclusion that it is a bug. It states quite emphatically in the MSDN that Launch Conditions WILL be...
12
4741
by: Prabu Subroto | last post by:
Dear my friends... I am using postgres 7.4 and SuSE 9.1. I want to use auto_increment as on MySQL. I look up the documentation on www.postgres.com and I found "serial" . But I don't know...
5
3441
by: Simon Verona | last post by:
I have an installer project for my VB.net application which as a custom action runs a silent installation of a third party software product. This however, generates an error if the application is...
6
6420
by: Takeadoe | last post by:
Dear NG, Can someone assist me with writing the little code that is needed to run an update table query each time the database is opened? From what I've been able to glean from this group, the...
1
1450
by: rehanmomin | last post by:
BACKGROUND I was trying the figure out a query for my sisters optometrist office. I have two tables, one that contains customers demographics and another table that contains patient's examination. ...
0
6437
by: bharathreddy | last post by:
This article will explain you how to check weather a column already exists in a table before you add the column to the table using alter command. Using the system tables...
4
5587
by: qwedster | last post by:
Howdy folks! I am using stored procedure to see if a value exists in database table and return 0 if exists or else -1, in the following SQL queries. However how to check if a value (that is...
2
14641
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
7120
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
7196
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...
1
6878
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.