PC Review


Reply
Thread Tools Rate Thread

CommandText with string variable

 
 
Doug Howell
Guest
Posts: n/a
 
      3rd Nov 2009
I currently have a bit of VBA that sets command text:

Set batchinfo4 = _
Sheets("pressuredata").QueryTables(1)
With batchinfo4
.CommandType = xlCmdSql
.CommandText = _
"SELECT PURP3.[TIME], PURP3.[PURP3PT1], PURP3.[PURP3JPT] FROM
PURP3.dbo.PURP3 PURP3 WHERE PURP3.[TIME] BETWEEN '" & Sheets("Pre-
Batch Checklist").Range("B3").Value & " 6:00:00 AM' AND '" & Sheets
("Pre-Batch Checklist").Range("B3").Value & " 10:00:00 PM'"
End With

I have a string variable "purtank" that I want to substitute in for
anywhere you see "PURP3" above.

What's the correct syntax for doing this?

Thanks for any help.


Doug
 
Reply With Quote
 
 
 
 
Nigel
Guest
Posts: n/a
 
      3rd Nov 2009
Since the select statement is a string you need to concatenate the text part
with variable name for example in the first part

"SELECT PURP3.[TIME],

becomes

"SELECT" & purtank & ".[TIME],

etc...

--

Regards,
Nigel
(E-Mail Removed)



"Doug Howell" <(E-Mail Removed)> wrote in message
news:98d9b8d3-ba7a-4ffd-83f3-(E-Mail Removed)...
>I currently have a bit of VBA that sets command text:
>
> Set batchinfo4 = _
> Sheets("pressuredata").QueryTables(1)
> With batchinfo4
> .CommandType = xlCmdSql
> .CommandText = _
> "SELECT PURP3.[TIME], PURP3.[PURP3PT1], PURP3.[PURP3JPT] FROM
> PURP3.dbo.PURP3 PURP3 WHERE PURP3.[TIME] BETWEEN '" & Sheets("Pre-
> Batch Checklist").Range("B3").Value & " 6:00:00 AM' AND '" & Sheets
> ("Pre-Batch Checklist").Range("B3").Value & " 10:00:00 PM'"
> End With
>
> I have a string variable "purtank" that I want to substitute in for
> anywhere you see "PURP3" above.
>
> What's the correct syntax for doing this?
>
> Thanks for any help.
>
>
> Doug


 
Reply With Quote
 
Doug Howell
Guest
Posts: n/a
 
      3rd Nov 2009
On Nov 3, 9:08*am, "Nigel" <ni...@no9swspam.co.uk> wrote:
> Since the select statement is a string you need to concatenate the text part
> with variable name for example in the first part
>
> "SELECT PURP3.[TIME],
>
> becomes
>
> "SELECT" & *purtank & ".[TIME],
>
> etc...
>
> --
>
> Regards,
> Nigel
> nigelnos...@9sw.co.uk
>
> "Doug Howell" <douglasehow...@hotmail.com> wrote in message
>
> news:98d9b8d3-ba7a-4ffd-83f3-(E-Mail Removed)...
>
>
>
> >I currently have a bit of VBA that sets command text:

>
> > Set batchinfo4 = _
> > * *Sheets("pressuredata").QueryTables(1)
> > With batchinfo4
> > * *.CommandType = xlCmdSql
> > * *.CommandText = _
> > * * * *"SELECT PURP3.[TIME], PURP3.[PURP3PT1], PURP3.[PURP3JPT]FROM
> > PURP3.dbo.PURP3 PURP3 WHERE PURP3.[TIME] BETWEEN '" & Sheets("Pre-
> > Batch Checklist").Range("B3").Value & " 6:00:00 AM' AND '" & Sheets
> > ("Pre-Batch Checklist").Range("B3").Value & " 10:00:00 PM'"
> > End With

>
> > I have a string variable "purtank" that I want to substitute in for
> > anywhere you see "PURP3" above.

>
> > What's the correct syntax for doing this?

>
> > Thanks for any help.

>
> > Doug- Hide quoted text -

>
> - Show quoted text -


Thanks!
 
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
setting a range variable equal to the value of a string variable Pilgrim Microsoft Excel Programming 2 1st Jul 2004 11:32 PM
PivotCache.CommandText - string length limitation in Excel 2000??? =?Utf-8?B?Y29ybmRvZw==?= Microsoft Excel Programming 0 12th Apr 2004 06:41 PM
PivotCache.CommandText - string length limitation in Excel 2000??? =?Utf-8?B?Y29ybmRvZw==?= Microsoft Excel Programming 0 7th Apr 2004 06:41 PM
PivotCache.CommandText - string length limitation in Excel 2000??? =?Utf-8?B?Y29ybmRvZw==?= Microsoft Excel Setup 1 6th Apr 2004 03:26 PM
String Length Limit for CommandText Venkatesh Microsoft ADO .NET 3 24th Sep 2003 10:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:07 PM.