Re: FROM (tablename) question?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: MaBell (MaBell_at_discussions.microsoft.com)
Date: 11/10/04


Date: Wed, 10 Nov 2004 07:44:09 -0800

Thanks. I got it to run using a string in VBA code but could you show me an
example of how to view the results or save it to use later?

   Dim conDatabase As ADODB.Connection
    Dim strSQL As String
    Dim TableName1 As String
    
    Set conDatabase = CurrentProject.Connection
    'To be populated on the fly
      TableName1 = "tblMFSFund"
   
    strSQL = "SELECT * FROM " & TableName1
    conDatabase.Execute strSQL
    
    conDatabase.Close
    Set conDatabase = Nothing

"Ken Snell [MVP]" wrote:

> You can do something like this using VBA code, where you build the SQL
> string into a variable, and then execute the query via VBA code.
>
> But if you want to have the query ask you for the tablename as a parameter
> when you run the query, as noted elsethread, the answer is no.
> --
>
> Ken Snell
> <MS ACCESS MVP>
>
>
> "MaBell" <MaBell@discussions.microsoft.com> wrote in message
> news:B7156F09-9816-4BB9-9580-A41BA06EE059@microsoft.com...
> > Can you setup a query to use a tablename passed as a parameterinstead of
> > hardcoded. I have multiple queries that are exactly the same except for
> table
> > name and I want just have one query and pass the table name depending on
> the
> > logic.
> >
> > Is that possible???
> > --
> >
> > Thanks in advance,
> > Matt
> > (access 2000)
>
>
>



Relevant Pages

  • Re: Problems with Delete Command
    ... The SQL could get fairly messy if you need to construct it in code, ... ContactID, and WebComID, and create your on-the-fly SQL on that saved query, ... to find the list of ContactIDs from the junction table, ... This is a style/readability thing: if you are going to use string ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Build Dynamic Query from Form
    ... I didn't follow the bit about why you "really need to this in the query" *instead* of in VBA code. ... Declare the parameters in your query, so JET knows their data type. ... I got it working in my Report, but all it does now is filter for dates, the ... Dim strDateCondition As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: Need help with Code Please!!!
    ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)
  • Re: Need help with Code Please!!!
    ... putting the query SQL itself in here maybe it will help you understand what I ... the actual string that gets built at the end of the SQ1 build process. ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ... Dim qd As QueryDef 'object ref to query item ...
    (microsoft.public.access.formscoding)
  • Re: Need help with Code Please!!!
    ... the actual string that gets built at the end of the SQ1 build process. ... The message says Syntax error in query expression ... Dim rs As Recordset 'object ref to qryCompany\USFNumber ...
    (microsoft.public.access.formscoding)