|
-
Jan 10th, 2002, 06:10 PM
#1
Access table check from VB 6
I have been searching high and low for answers to basic questions about String Theory, but I thought I'd lower myself to VB and Access.
So far I've figured out how to delete tables from the database, how to compact it from VB and how to otherwise manipulate records in tables. But...
What I need to do is test for the existence of a specific table in an Access database before trying to delete it. If the table is there, it deletes. If not, it abends (old COBOL word...) and tells me that the item is not found in the collection.
Along a similar vein, can I use wildcards to delete everything at once regardless of the name(s)? That way I wouldn't have to look for a specific table...
<sigh> I really do miss Delphi...
-
Jan 10th, 2002, 07:13 PM
#2
PowerPoster
Do a search for DAO and tabledefs!
If you dont find anything reply back!
good luck
b
-
Jan 11th, 2002, 06:05 AM
#3
Hi
VB Code:
dim strTablename as string
on error resume next
strtablename=dbengine(0)(0).tabledefs("tablename").name
if err.number=0 then dbengine(0)(0).tabledefs("tablename").delete
Where "tablename" can be replaced by an index number or string of table name.
NOTE : Access uses system tables which you shouldn't mess about with... (starting with msys....)
The above can be checked, if you get a name just do something like
VB Code:
if not strtablename like "msys* then dbengine(0)(0).tabledefs("tablename").delete
Is that what you wanted ?
Regards
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
-
Jan 11th, 2002, 12:17 PM
#4
Vince,
It's been a while since I've used Access VB. I say this because I remember something about calling the DB using (0) (0). I also have been told that Access 2000 code is VB 6 code. Nope. Not on a direct 1-to-1 basis. VB 6 doesn't use "DoCmd.DeleteObject" because I tried copy-paste with Access 2K code into VB 6 and it puked on the "DoCmd" statement.
I'll give it a shot and let you know.
Oh, one more thing...
When I tried stepping through the tables using a for..next loop, it skipped every other table. I used:
for i = 0 to <table.count>
<delete>
next i
and
for each td in db
<delete>
next td
The result was that before the code hit the "Next" statement, the table name changed. Then the tablename changed again when it hit the "For" statement which kicked me down to the record after what should have been the next one.
Am I seeing things, or is this an MS undocumented feature?
Randy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|