Results 1 to 14 of 14
  1. #1
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365

    Avoideing error 3265

    Is there a method for seeing if a Table Exists?



    I was using If IsObject(CurrentDb.TableDefs("Table11")) Then but this doesn't return true or false but 3265 Item not found in this collection if the table is not there.

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by Bob Fitz View Post
    Now there is a novel idea Bob
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2019
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Quote Originally Posted by Welshgasman View Post
    Now there is a novel idea Bob
    Yes. All this "thinking outside the box" is all well and good but sometimes it's better to think inside it
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I hope the table name isn't really "Table11"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    It was Google where I found the routine that went to error. I ended up with
    Code:
    Function TableExists() As Boolean
        Dim tbldef As TableDef
        For Each tbldef In CurrentDb.TableDefs
           If tbldef.Name = "Table11" Then
              TableExists = True
              Exit Function
           End If
        Next tbldef
    End Function
    But it it really necessary to look through each table name ?
    BTW What's wring with the name "Table11" ? It's generated by Access after a Saved ImportExport.
    It's actually "Table1" but if that exists the new import calls it "Table11", "Table12". etc.

  7. #7
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why are you importing to new table instead of existing?

    If Access is assigning table name, how do you know what name to look for?

    If you don't want to loop, can use error handling code.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    DoCmd.RunSavedImportExport won't write an an existing table, will it ? If yes, that'd make it much more straightforward.
    I know what Access will call it, if it's deleted.
    My logic was to avoid error handling as it isn't an error, but see what you mean.

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Yes, you can.

    Create table first. Manually perform an import to existing table and save. Now it is available to run with code.

    Worked for me.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    That's really weird. I'm sure there's only one way to do that. Mine will not use an existing table and calls it the same as the source table, (with "1" added if it exists).
    I did try selecting a table first (which works for Exporting) but no change.

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What are you importing from?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  12. #12
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    From a table in .accdb file.

  13. #13
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Okay, I tested import from Excel (making wrong assumption).

    With Access source wizard options are to import as new table or set a link.

    Why don't you just set a link? If you really need to load into local table, can then run INSERT SELECT action.

    Or don't set a link and run an INSERT SELECT SQL action to pull directly from other table into existing local table.

    Simple example:

    INSERT INTO Airports SELECT * FROM Airports IN "C:\Users\June\Airports\AirportsAdmin.accdb";

    That example works because there is no autonumber ID field involved and fields are same and same order in both tables. Otherwise, will likely be a little more complicated.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    Middlemarch is offline Competent Performer
    Windows 10 Access 2019
    Join Date
    Mar 2015
    Posts
    365
    I've set up 4 saved imports with 60 fields and special text/field delimiters! Your method would have ben easier that's for sure... but its all in and working now.
    I need it be called Table11 though. And there is an ID autonumber field but I don't think its used.
    It has 'come right' now with Drop Table only used if it exists. But any more trouble and I'll try your Insert Into.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Runtime error 3265
    By Dave_D in forum Programming
    Replies: 4
    Last Post: 11-20-2020, 05:35 PM
  2. Replies: 6
    Last Post: 04-20-2018, 04:45 AM
  3. Create Querydef - Error 3265
    By Tim1 in forum Programming
    Replies: 3
    Last Post: 04-25-2016, 09:12 AM
  4. Run-Time Error '3265': Item Not Found In This Collection
    By Voodeux2014 in forum Programming
    Replies: 3
    Last Post: 01-29-2016, 09:04 AM
  5. Run Time Error 3265
    By duckie10 in forum Access
    Replies: 5
    Last Post: 05-13-2009, 09:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums