PC Review


Reply
Thread Tools Rate Thread

Can I use a variable for a table name in an SQL statement using VB

 
 
ambushsinger
Guest
Posts: n/a
 
      24th May 2010
Can I use a variable for a table name in an SQL statement using VBA
 
Reply With Quote
 
 
 
 
John Spencer
Guest
Posts: n/a
 
      24th May 2010
The answer is Yes. Since you posted no details I can only give you a simple
example.

Dim strSQL as String
Dim tblName as String

strSQL = "SELECT A.Field1, A.Field2" & _
" FROM [" & tblName & "] as A INNER JOIN SomeTable"
" ON A.SomeField = SomeTable.SomeMatchingField"



John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

ambushsinger wrote:
> Can I use a variable for a table name in an SQL statement using VBA

 
Reply With Quote
 
ambushsinger
Guest
Posts: n/a
 
      25th May 2010
Excellent...it works, Thanks

"John Spencer" wrote:

> The answer is Yes. Since you posted no details I can only give you a simple
> example.
>
> Dim strSQL as String
> Dim tblName as String
>
> strSQL = "SELECT A.Field1, A.Field2" & _
> " FROM [" & tblName & "] as A INNER JOIN SomeTable"
> " ON A.SomeField = SomeTable.SomeMatchingField"
>
>
>
> John Spencer
> Access MVP 2002-2005, 2007-2010
> The Hilltop Institute
> University of Maryland Baltimore County
>
> ambushsinger wrote:
> > Can I use a variable for a table name in an SQL statement using VBA

> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use a variable for a table name in a SQL statement using VBA ambushsinger Microsoft Access VBA Modules 1 21st May 2010 04:58 PM
Variable table/field name in statement Stu Microsoft Access VBA Modules 7 29th May 2008 03:58 PM
Using a SQL statement with variable parameters and variable criteria Froefel Microsoft ASP .NET 1 4th Jul 2007 10:38 AM
Macro Creating Variable and using variable in a SQL statement =?Utf-8?B?SmltbXk=?= Microsoft Excel Programming 4 25th Oct 2004 02:36 AM
Re: Pivot Table - Object variable or with block variable not set? George Nicholson Microsoft Excel Programming 1 16th Apr 2004 09:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:51 PM.