Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Guest ji, please consider donating today!
      Become a Supporter    ::   Make a Contribution   
    Monthly Recurring Target: $300 :: Achieved: $95

Re: Create query in temporary DB

Discussion in 'Information Technology' started by Douglas J Steele, Oct 26, 2005.

  1. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    The reason you're not seeing the query is because you're not naming it.

    Put a query name in:

    Set qdfNew = dbsTemp.CreateQueryDef(strQueryName)


    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Parker" <ParkerPierce@gmail.com> wrote in message
    news:1130271256.913246.92460@z14g2000cwz.googlegroups.com...
    > I am using a temporary db (created in code) to solve my mdb file size
    > growth problem. I have successfully created the tables I need in code,
    > used them, and deleted the temp DB on exit. However, I also have a
    > number of queries that are created on the fly. These are causing my
    > file size to bloat as well. I am trying to create these in the same way
    > I created the temp tables, but I cannot get it to work. Any help will
    > be immensely appreciated. Here is the code I am trying to use:
    > 'CREATE QUERY IN TEMP DB
    > strQueryName = "searchQuery_Temp"
    >
    > ' Delete the link to the temp query if it exists
    > If queryExists(strQueryName) Then
    > CurrentDb.QueryDefs.Delete strQueryName
    > End If
    >
    > ' Create the temp query
    > Set qdfNew = dbsTemp.CreateQueryDef("")
    > With qdfNew
    > .Connect = "ODBC;DATABASE=" & strTempDatabase &
    > "DSN=Search_Table_Temp"
    > .SQL = "SELECT * from Search_Table_Temp;"
    > 'Set rs = dbsTemp.OpenRecordset()
    > End With
    >
    > dbsTemp.QueryDefs.Refresh
    >
    > When using this code, I cannot get the query to appear in the temp DB
    > database window or in the current DB's window. Also, here is the code I
    > used to link the temp tables to my current DB. I cannot figure out how
    > to mofidiy this to work for the queries:
    > ' Link to the Import tables in the temp MDB
    > Set tdfLinked = CurrentDb.CreateTableDef(strTableName)
    > tdfLinked.Connect = ";DATABASE=" & strTempDatabase
    > tdfLinked.SourceTableName = strTableName
    > CurrentDb.TableDefs.Append tdfLinked
    >
     
  2. Loading...


  3. Parker

    Parker
    Expand Collapse
    Guest

    I put the name in there and now it shows up in my TempDB. However,
    there are still two problems. First, if I open up the TempDB I can see
    the query in the db window, but if I try to open it a "Select Data
    Source" dialog box opens instead of the query result. What is going on
    here? Second, I still cannot figure out how to connect it to the
    CurrentDB so that I can see it in the CurrentDB's database window (like
    I can with the temp tables). Thanks again for your help.

    Douglas J Steele wrote:
    > The reason you're not seeing the query is because you're not naming it.
    >
    > Put a query name in:
    >
    > Set qdfNew = dbsTemp.CreateQueryDef(strQueryName)
    >
    >
    > --
    > Doug Steele, Microsoft Access MVP
    > http://I.Am/DougSteele
    > (no e-mails, please!)
    >
    >
    > "Parker" <ParkerPierce@gmail.com> wrote in message
    > news:1130271256.913246.92460@z14g2000cwz.googlegroups.com...
    > > I am using a temporary db (created in code) to solve my mdb file size
    > > growth problem. I have successfully created the tables I need in code,
    > > used them, and deleted the temp DB on exit. However, I also have a
    > > number of queries that are created on the fly. These are causing my
    > > file size to bloat as well. I am trying to create these in the same way
    > > I created the temp tables, but I cannot get it to work. Any help will
    > > be immensely appreciated. Here is the code I am trying to use:
    > > 'CREATE QUERY IN TEMP DB
    > > strQueryName = "searchQuery_Temp"
    > >
    > > ' Delete the link to the temp query if it exists
    > > If queryExists(strQueryName) Then
    > > CurrentDb.QueryDefs.Delete strQueryName
    > > End If
    > >
    > > ' Create the temp query
    > > Set qdfNew = dbsTemp.CreateQueryDef("")
    > > With qdfNew
    > > .Connect = "ODBC;DATABASE=" & strTempDatabase &
    > > "DSN=Search_Table_Temp"
    > > .SQL = "SELECT * from Search_Table_Temp;"
    > > 'Set rs = dbsTemp.OpenRecordset()
    > > End With
    > >
    > > dbsTemp.QueryDefs.Refresh
    > >
    > > When using this code, I cannot get the query to appear in the temp DB
    > > database window or in the current DB's window. Also, here is the code I
    > > used to link the temp tables to my current DB. I cannot figure out how
    > > to mofidiy this to work for the queries:
    > > ' Link to the Import tables in the temp MDB
    > > Set tdfLinked = CurrentDb.CreateTableDef(strTableName)
    > > tdfLinked.Connect = ";DATABASE=" & strTempDatabase
    > > tdfLinked.SourceTableName = strTableName
    > > CurrentDb.TableDefs.Append tdfLinked
    > >
     
  4. Douglas J Steele

    Douglas J Steele
    Expand Collapse
    Guest

    I don't believe your Connect property is correct (you're missing a
    semi-colon before the keyword DSN). However, what's strTempDatabase? If it's
    a Jet database (i.e. an MDB), you can't use ODBC to connect to it from
    Access)

    You cannot create the equivalent of linked queries. In other words, there's
    no way for you to see it in your front-end.

    --
    Doug Steele, Microsoft Access MVP
    http://I.Am/DougSteele
    (no e-mails, please!)


    "Parker" <ParkerPierce@gmail.com> wrote in message
    news:1130335984.411654.94020@o13g2000cwo.googlegroups.com...
    > I put the name in there and now it shows up in my TempDB. However,
    > there are still two problems. First, if I open up the TempDB I can see
    > the query in the db window, but if I try to open it a "Select Data
    > Source" dialog box opens instead of the query result. What is going on
    > here? Second, I still cannot figure out how to connect it to the
    > CurrentDB so that I can see it in the CurrentDB's database window (like
    > I can with the temp tables). Thanks again for your help.
    >
    > Douglas J Steele wrote:
    > > The reason you're not seeing the query is because you're not naming it.
    > >
    > > Put a query name in:
    > >
    > > Set qdfNew = dbsTemp.CreateQueryDef(strQueryName)
    > >
    > >
    > > --
    > > Doug Steele, Microsoft Access MVP
    > > http://I.Am/DougSteele
    > > (no e-mails, please!)
    > >
    > >
    > > "Parker" <ParkerPierce@gmail.com> wrote in message
    > > news:1130271256.913246.92460@z14g2000cwz.googlegroups.com...
    > > > I am using a temporary db (created in code) to solve my mdb file size
    > > > growth problem. I have successfully created the tables I need in code,
    > > > used them, and deleted the temp DB on exit. However, I also have a
    > > > number of queries that are created on the fly. These are causing my
    > > > file size to bloat as well. I am trying to create these in the same

    way
    > > > I created the temp tables, but I cannot get it to work. Any help will
    > > > be immensely appreciated. Here is the code I am trying to use:
    > > > 'CREATE QUERY IN TEMP DB
    > > > strQueryName = "searchQuery_Temp"
    > > >
    > > > ' Delete the link to the temp query if it exists
    > > > If queryExists(strQueryName) Then
    > > > CurrentDb.QueryDefs.Delete strQueryName
    > > > End If
    > > >
    > > > ' Create the temp query
    > > > Set qdfNew = dbsTemp.CreateQueryDef("")
    > > > With qdfNew
    > > > .Connect = "ODBC;DATABASE=" & strTempDatabase &
    > > > "DSN=Search_Table_Temp"
    > > > .SQL = "SELECT * from Search_Table_Temp;"
    > > > 'Set rs = dbsTemp.OpenRecordset()
    > > > End With
    > > >
    > > > dbsTemp.QueryDefs.Refresh
    > > >
    > > > When using this code, I cannot get the query to appear in the temp DB
    > > > database window or in the current DB's window. Also, here is the code

    I
    > > > used to link the temp tables to my current DB. I cannot figure out how
    > > > to mofidiy this to work for the queries:
    > > > ' Link to the Import tables in the temp MDB
    > > > Set tdfLinked = CurrentDb.CreateTableDef(strTableName)
    > > > tdfLinked.Connect = ";DATABASE=" & strTempDatabase
    > > > tdfLinked.SourceTableName = strTableName
    > > > CurrentDb.TableDefs.Append tdfLinked
    > > >

    >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page