473,405 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

How to avoid inadvertently hiding tables when using Select..Into?

beacon
579 512MB
Hi everybody,

[Access 2010]

I'm not sure if the subject will ultimately describe my issue, but it was the best I could come up with based on the info I've got.

I'm working on a database that I inherited from a previous employee and it's very basic, at least in terms of objects...there's only tables and queries, no code. However, the queries depend on other queries in order to perform their functions, i.e. a Make Table query creates a table that is used in the definition of a second query.

Due to the large number of queries the dependency, I wanted to automate the entire process. Because I'm working with Make Table queries, one of the steps I have to complete is to delete the table that the Make Table query produces since the Make Table query may be used multiple times in a loop (changing the table used in the definition of the query each iteration).

So, I'm attempting to loop through the TableDefs collection looking for the table names that the Make Table query is supposed to create each iteration. The problem that I'm running into though, is that my loop through TableDefs doesn't always find a particular table...almost as if it's hidden. I can unhide the hidden tables and the table is there, but the table properties don't show the table to be hidden. I've stepped through the code to see each of the table names that are available in the TableDefs loop, but for some reason the table isn't found.

This leads me to another problem that I alluded to, which is that I can't use the Make Table query if the table created by the query already exists (it produces error 3010).

I'm stumped as to why the table isn't showing up in the TableDefs collection. Can anyone tell me why this is occurring?

Here's my code...I'll break it up into snippets and provide some info on what I'm trying to do at each step:

Declare variable, assign Table/QueryDefs to variables, create an array of table names that will be used in the query definition (changing at the For..Loop iteration) for the "Add TPI" query.
Expand|Select|Wrap|Line Numbers
  1.     Dim db As DAO.Database
  2.     Dim td As DAO.TableDefs
  3.     Dim t As Object
  4.     Dim qdfBigCountP1 As DAO.QueryDef
  5.     Dim qdfBigCountP2 As DAO.QueryDef
  6.     Dim qdfBigCountP3 As DAO.QueryDef
  7.     Dim qdfBigCountP4 As DAO.QueryDef
  8.     Dim qdfEligibilityCheck As DAO.QueryDef
  9.     Dim strBigCountP1SQL As String
  10.     Dim strBigCountP3SQL As String
  11.     Dim strBigCountP4SQL As String
  12.     Dim strEligibilityCheckSQL As String
  13.     Dim arrTables(1) As String
  14.     Dim countTable As Integer
  15.     Dim strTable As String
  16.     Dim strWrap As String
  17.     Dim strNoWrap As String
  18.     Dim blnTablesFound As Boolean
  19.  
  20.     Set db = CurrentDb()
  21.     Set td = db.TableDefs
  22.     Set qdfBigCountP1 = db.QueryDefs("Big Count P1")
  23.     Set qdfBigCountP2 = db.QueryDefs("Big Count P2")
  24.     Set qdfBigCountP3 = db.QueryDefs("Big Count P3")
  25.     Set qdfBigCountP4 = db.QueryDefs("Big Count P4")
  26.     Set qdfEligibilityCheck = db.QueryDefs("Eligibility Check")
  27.  
  28.     arrTables(0) = "Title V Selected Providers (Jan 15th)"
  29.     arrTables(1) = "Title XX Selected Providers (Jan 15th)"
  30.  
Start the main For..Loop, the strWrap and strNoWrap values are important for the hidden table problem, then I assign new SQL to the queries used.
Expand|Select|Wrap|Line Numbers
  1.     For countTable = 0 To UBound(arrTables)
  2.         strTable = arrTables(countTable)
  3.  
  4.         Select Case countTable
  5.             Case 0
  6.                 strWrap = "Undup Title V Wrap (Jan 15th)"
  7.                 strNoWrap = "Undup Title V No Wrap (Jan 15th)"
  8.             Case 1
  9.                 strWrap = "Undup Title XX Wrap (Jan 15th)"
  10.                 strNoWrap = "Undup Title XX No Wrap (Jan 15th)"
  11.             Case Else
  12.                 Debug.Print "An error occurred in the Select..Case Statement"
  13.         End Select
  14.  
  15.         td.Refresh
  16.  
  17.         strBigCountP1SQL = "SELECT [" & strTable & "].Provider, [" & strTable & "].PCN, [" & strTable & "].FDOS, [" & strTable & "].[Claim Type], [" & strTable & "].SSN, " & _
  18.                            "[" & strTable & "].[Procedure Code], [" & strTable & "].[Current Claim Status], [" & strTable & "].Sex, FiscalYearAge([" & strTable & "].DOB) " & _
  19.                            "AS Age, [" & strTable & "].[Allowed Quantity], [" & strTable & "].[Billed Quantity], [" & strTable & "].[Modifier 1], [" & strTable & "].Paid, " & _
  20.                            "[" & strTable & "].[DHS County Code], [" & strTable & "].TPI INTO [Core Count P1] FROM [" & strTable & "] WHERE (((" & _
  21.                            "[" & strTable & "].[Current Claim Status])<>'D'));"
  22.  
  23.         qdfBigCountP1.SQL = strBigCountP1SQL
  24.         qdfBigCountP1.Close
  25.  
  26.         strEligibilityCheckSQL = "SELECT [" & strTable & "].* FROM [" & strTable & "] INNER JOIN [WHP SSN Undup] ON [" & strTable & "].SSN=[WHP SSN Undup].SSN " & _
  27.                                  "WHERE ((([" & strTable & "].FDOS) Between [Beginning Eligibility] And [Ending Eligibility]) AND ((" & _
  28.                                  "[" & strTable & "].[Current Claim Status])<>'D'));"
  29.  
  30.         qdfEligibilityCheck.SQL = strEligibilityCheckSQL
  31.         qdfEligibilityCheck.Close
  32.  
  33.         strBigCountP3SQL = "SELECT [Core Count P1].Provider, [Core Count P1].PCN, [Core Count P1].[Current Claim Status], [Core Count P1].[Procedure Code], " & _
  34.                            "[Core Count P1].SSN, Sum([Core Count P1].[Billed Quantity]) AS [Billed Quantity], Sum([Core Count P1].[Allowed Quantity]) AS [Allowed Quantity], " & _
  35.                            "First([Core Count P1].[Claim Type]) AS [Claim Type], Sum([Core Count P1].Paid) AS Paid, First([Core Count P1].Sex) AS Sex, " & _
  36.                            "First([Core Count P1].Age) AS Age, First([Core Count P1].[Modifier 1]) AS [Modifer 1] INTO [" & strNoWrap & "] FROM [Core Count P1] GROUP BY " & _
  37.                            "[Core Count P1].Provider, [Core Count P1].PCN, [Core Count P1].[Current Claim Status], [Core Count P1].[Procedure Code], [Core Count P1].SSN;"
  38.  
  39.         qdfBigCountP3.SQL = strBigCountP3SQL
  40.         qdfBigCountP3.Close
  41.  
  42.         strBigCountP4SQL = "SELECT [Eligibility Check].Provider, [Eligibility Check].PCN, [Eligibility Check].FDOS, [Eligibility Check].[Procedure Code], " & _
  43.                            "[Eligibility Check].[Current Claim Status], [Eligibility Check].SSN, First([Eligibility Check].[Claim Type]) AS [Claim Type], " & _
  44.                            "Sum([Eligibility Check].Paid) AS Paid, Sum([Eligibility Check].[Allowed Quantity]) AS [Allowed Quantity], " & _
  45.                            "Sum([Eligibility Check].[Billed Quantity]) AS [Billed Quantity], [Eligibility Check].[Modifier 1] AS [Modifer 1], " & _
  46.                            "First([Eligibility Check].Sex) AS Sex, First(FiscalYearAge([Eligibility Check].DOB)) AS Age, [Eligibility Check].[DHS County Code], " & _
  47.                            "[Eligibility Check].TPI INTO [" & strWrap & "] FROM [Eligibility Check] GROUP BY [Eligibility Check].Provider, [Eligibility Check].PCN, " & _
  48.                            "[Eligibility Check].FDOS, [Eligibility Check].[Procedure Code], [Eligibility Check].[Current Claim Status], [Eligibility Check].SSN, " & _
  49.                            "[Eligibility Check].[Modifier 1], [Eligibility Check].[DHS County Code], [Eligibility Check].TPI;"
  50.  
  51.         qdfBigCountP4.SQL = strBigCountP4SQL
  52.         qdfBigCountP4.Close
  53.  
  54.         td.Refresh
  55.  
This is still in the main For..Loop. The next For..Loop looks for the "Core Count P1" table in the TableDefs collection (no problem here), then the next For..Loop looks for the tables that are assigned to the strWrap and strNoWrap tables (I use the boolean value to try to delete both tables in the loop while also being able to exit the loop without having to iterate through everything in the TableDefs collection). Then I execute each of the QueryDefs...qdfBigCountP3.Execute and/or qdfBigCount4.Execute have been throwing the 3010 error because those tables create the Wrap and No Wrap tables.
Expand|Select|Wrap|Line Numbers
  1.         For Each t In td
  2.             If t.Name = "Core Count P1" Then
  3.                 td.Delete "Core Count P1"
  4.                 Debug.Print "The Core Count P1 table was found and deleted."
  5.                 Exit For
  6.             End If
  7.         Next t
  8.  
  9.         td.Refresh
  10.  
  11.         blnTablesFound = False
  12.  
  13.         For Each t In CurrentDb.TableDefs
  14.             Debug.Print t.Name
  15.             If t.Name = strWrap Then
  16.                 td.Delete strWrap
  17.                 Debug.Print "The " & strWrap & " table was found and deleted."
  18.                 Debug.Print blnTablesFound
  19.                 If blnTablesFound = True Then
  20.                     Exit For
  21.                 Else
  22.                     blnTablesFound = True
  23.                 End If
  24.             ElseIf t.Name = strNoWrap Then
  25.                 td.Delete strNoWrap
  26.                 Debug.Print "The " & strNoWrap & " table was found and deleted."
  27.                 Debug.Print blnTablesFound
  28.                 If blnTablesFound = True Then
  29.                     Exit For
  30.                 Else
  31.                     blnTablesFound = True
  32.                 End If
  33.             End If
  34.         Next t
  35.  
  36.         qdfBigCountP1.Execute dbFailOnError
  37.         qdfBigCountP2.Execute dbFailOnError
  38.         qdfBigCountP3.Execute dbFailOnError
  39.         qdfBigCountP4.Execute dbFailOnError
  40.  
  41.     Next countTable
  42.  
  43.     Set qdfEligibilityCheck = Nothing
  44.     Set qdfBigCountP4 = Nothing
  45.     Set qdfBigCountP3 = Nothing
  46.     Set qdfBigCountP2 = Nothing
  47.     Set qdfBigCountP1 = Nothing
  48.     Set qdfBigCountP1 = Nothing
  49.     Set td = Nothing
  50.     Set db = Nothing
  51.  
  52. End Sub
  53.  
Any ideas? Sorry for the super long post, but I wanted to make sure I provided enough info.

Thanks,
beacon
Sep 7 '12 #1
3 1529
beacon
579 512MB
Never mind...I figured it out. For some reason I used:

Expand|Select|Wrap|Line Numbers
  1. Dim t as Object
  2.  
...instead of:

Expand|Select|Wrap|Line Numbers
  1. Dim t as DAO.TableDef
  2.  
I don't have any clue why I used Object instead of TableDef,, but, as is usually the case, as soon as I post something here I see the error.

Thanks,
beacon
Sep 7 '12 #2
beacon
579 512MB
I have a follow up to this that I'm hoping someone can answer. I had the following line in my code:

Expand|Select|Wrap|Line Numbers
  1. For each t in td
  2.  
...and when the subroutine completed, the tables created by the Make Table query are still hidden or, at least, don't show up in the Navigation Pane.

When I change the line to:

Expand|Select|Wrap|Line Numbers
  1. For each t in CurrentDB.TableDefs
  2.  
...it appears to work and make the newly created tables appear in the Navigation Pane.

Why would using 'td' over 'CurrentDB.TableDefs' make a difference if 'td' is a variable that is assigned to 'db.TableDefs' in my code? Can anyone explain why the tables created by the Make Table query would be hidden?

Thanks,
beacon
Sep 7 '12 #3
zmbd
5,501 Expert Mod 4TB
It may be the use of parentheses
I know it sounds crazy... but try it
(1) set td=CurrentDB not
(2) set td=CurrentDB()

It has to do with another way of referring to the database
(3) DBEngine.Workspaces(0).Databases(0)

From what little I understand, (1) has a more direct relationship to the user graphical interface...
Really, I don't understand it anymore than that nor have I done any research into the differences. What I do know is that when I accidentally use (2) that when I type that first "(" I am prompted for an item index as a table definition and therein may lay the issue (just an educated guess... )

-z
Sep 7 '12 #4

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

Similar topics

4
by: timmy | last post by:
I have a table with a cell on the bottom right with an image to create a rounded corner effect: <table cellpadding="0" cellspacing="0" border="1"> <tr><td rowspan="2">asdfsadf</td> <td...
8
by: skinnybloke | last post by:
Hi - I have a problem with a memo field being truncated to about 255 characters when running a Access 2002 query. This only seems to happen if I use SELECT DISTINCT. It works ok using SELECT by...
2
by: skinnybloke | last post by:
Hi - I have a problem with a memo field being truncated to about 255 characters when running a Access 2002 query. This only seems to happen if I use SELECT DISTINCT. It works ok using SELECT by...
4
by: prashantkumar1982 | last post by:
I am using the select call to read from many sockets. I don't want to call read on every socket to check if it is closed, as it defeats the purpose of using the select call. Is there any way to...
4
by: satish | last post by:
Values of two columns in two different tables--presentation using select Hi Everyone, i have two tables in the database . One is called address table and one is adressPhone Table. Below...
6
by: himilecyclist | last post by:
I am trying to use the SQL "SELECT INTO" to create a copy of a MySQL database. My PHP code looks like this: <?php //Connect to server and database include ("Connections/ovrs.inc");
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
5
by: bitsnbytes64 | last post by:
Hi, I have a test form with: * textbox txtIXO_NR bound to column IXO_NR through the linked SQL Server 2005 table TXOCTC (link name "dbo_TXOCTC") * an unbound textbox which should display the...
1
by: myschelle848691 | last post by:
Hi Guys, So i've just been told that SELECT INTO cannot be used within a scalar function. Can anyone please tell me why? Secondly, can I use a cursor on a view? and all within a function? ...
8
JamieHowarth0
by: JamieHowarth0 | last post by:
Hi folks, Got a problem - I've got all my automated emails (in HTML format) stored in a table in my DB (called tbl_emails). I've set up a trigger so that every time a new user registers (data put...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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...
0
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...

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.