Results 1 to 4 of 4
  1. #1
    merebag is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    19

    VBA example of dropping temp tables in MS SQL server


    One of the processes I have in my old Access ADP project was working with temp tables. How would I do something like this in my VBA code using ODBC to my SQL server?

    IF OBJECT_ID('tempdb..#TmpActive" & AuditID & "') IS NOT NULL DROP TABLE #TmpActive" & AuditID

    The process looks to see if there is already a temp table called TmpActive(with the user ID appended to it). If it exists, it drops it.

    I can't use the access docmd of .runSQL. Nor can I use a DAO recordset. Any clues?

    Thanks

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I have not looked at everything very closely, but the first thing that jumps out at me is that the temp table is something on SQL server itself, as opposed to a table in Access..

    Do you know for sure where the temp tables are/created? If they reside on the SQL server, you can connect to the server with the appropriate credentials and DROP via ODBC. So, not via DAO, but using a passthrough query. So whatever SQL works on the server should work in your passthrough.

  3. #3
    merebag is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Sep 2016
    Posts
    19
    Quote Originally Posted by ItsMe View Post
    I have not looked at everything very closely, but the first thing that jumps out at me is that the temp table is something on SQL server itself, as opposed to a table in Access..

    Do you know for sure where the temp tables are/created? If they reside on the SQL server, you can connect to the server with the appropriate credentials and DROP via ODBC. So, not via DAO, but using a passthrough query. So whatever SQL works on the server should work in your passthrough.
    Yes, the temp tables are on the SQL server. There are no local tables used in my access app. So, passthrough query should be the way to go from what you are saying. I will look at that option. Thanks

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You can create, save, and name a passthrough query. If you have trouble saving the SQL syntax necessary, you can assign the SQL statement to the SQL property of a saved Passthrough Query. You can access the properties of saved Query Objects in access via VBA, using the DAO QueryDefs collection. I should have some sample code around here somewhere if you get stuck
    .

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

Similar Threads

  1. temp tables
    By vicsaccess in forum Programming
    Replies: 7
    Last Post: 03-20-2016, 11:38 AM
  2. Replies: 1
    Last Post: 09-03-2014, 10:48 AM
  3. Replies: 3
    Last Post: 05-20-2013, 04:18 PM
  4. Dropping/deleting linked tables in VBA or query
    By dumbledown in forum Access
    Replies: 3
    Last Post: 04-05-2012, 08:43 AM
  5. Question About Temp Tables
    By Rawb in forum Database Design
    Replies: 4
    Last Post: 11-29-2010, 10:57 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