Results 1 to 4 of 4

Thread: Access table check from VB 6

  1. #1
    State Guy
    Guest

    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...

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Do a search for DAO and tabledefs!
    If you dont find anything reply back!
    good luck
    b

  3. #3
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Hi

    VB Code:
    1. dim strTablename as string
    2.  
    3. on error resume next
    4.  
    5. strtablename=dbengine(0)(0).tabledefs("tablename").name
    6. 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:
    1. if not strtablename like "msys* then dbengine(0)(0).tabledefs("tablename").delete

    Is that what you wanted ?

    Regards

    Vince

    BOFH Now, BOFH Past, Information on duplicates

    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...

  4. #4
    State Guy
    Guest
    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
  •  



Click Here to Expand Forum to Full Width