Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro Creating Variable and using variable in a SQL statement

Created a Variable where someone enters a date into a inputbox

eg. StartDate = InputBox("Enter Start Date?", "Report")

Then i used this variable in the SQL statement by saying

date=Startdate in the where clause in the VB script.

Instead of using the variable it tried to put "startdate" in the field and
filter by "startdate"

How do i make the the macro use the variable in the SQL statement.

Also should i be changing the date in a date format for the variable in the
inputbox statement. Because it is currently under no format. How can i change
this format.

Thanks If anyone can help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro Creating Variable and using variable in a SQL statement

Use

...date=""" & Format(Startdate,"yyyy/mm/dd") & """ ...

--

HTH

RP

"Jimmy" wrote in message
...
Created a Variable where someone enters a date into a inputbox

eg. StartDate = InputBox("Enter Start Date?", "Report")

Then i used this variable in the SQL statement by saying

date=Startdate in the where clause in the VB script.

Instead of using the variable it tried to put "startdate" in the field and
filter by "startdate"

How do i make the the macro use the variable in the SQL statement.

Also should i be changing the date in a date format for the variable in

the
inputbox statement. Because it is currently under no format. How can i

change
this format.

Thanks If anyone can help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 103
Default Macro Creating Variable and using variable in a SQL statement

dim sql as string
dim sDate as string
sdate = format$( InputBox("Enter Start Date?", "Report") , "dd-mmm-yy")
sql = "usp_FetchData '%d%'"

sql = REPLACE(sql, "%d%", sDate)



--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Jimmy" wrote in message
...
Created a Variable where someone enters a date into a inputbox

eg. StartDate = InputBox("Enter Start Date?", "Report")

Then i used this variable in the SQL statement by saying

date=Startdate in the where clause in the VB script.

Instead of using the variable it tried to put "startdate" in the field and
filter by "startdate"

How do i make the the macro use the variable in the SQL statement.

Also should i be changing the date in a date format for the variable in
the
inputbox statement. Because it is currently under no format. How can i
change
this format.

Thanks If anyone can help



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Macro Creating Variable and using variable in a SQL statement

Question

dim sql as string
dim sDate as string


sql = "usp_FetchData '%d%'"

sql = REPLACE(sql, "%d%", sDate)


Do i have to put this only once in the Macro or before every SQL script

What does sql = REPLACE(sql, "%d%", sDate) actually do?

And what does %d% represent?

In the sql statement to i write date=sdate or as date=%d% in the 'where'
clause.

Thanks

"Patrick Molloy" wrote:

dim sql as string
dim sDate as string
sdate = format$( InputBox("Enter Start Date?", "Report") , "dd-mmm-yy")
sql = "usp_FetchData '%d%'"

sql = REPLACE(sql, "%d%", sDate)



--
Patrick Molloy
Microsoft Excel MVP
---------------------------------
I Feel Great!
---------------------------------
"Jimmy" wrote in message
...
Created a Variable where someone enters a date into a inputbox

eg. StartDate = InputBox("Enter Start Date?", "Report")

Then i used this variable in the SQL statement by saying

date=Startdate in the where clause in the VB script.

Instead of using the variable it tried to put "startdate" in the field and
filter by "startdate"

How do i make the the macro use the variable in the SQL statement.

Also should i be changing the date in a date format for the variable in
the
inputbox statement. Because it is currently under no format. How can i
change
this format.

Thanks If anyone can help




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Macro Creating Variable and using variable in a SQL statement


Jimmy

It sounds like in your SQL command you have "StartDate" (inside quot
marks).
You need to remove the quote marks to enable VB to see the variable

I have not played around with sql but you may need to do something lik
this to enable your StartDate variable

"SqlTextCode" & StartDate & "MoreSqlTxtCode

--
mudrake
-----------------------------------------------------------------------
mudraker's Profile: http://www.excelforum.com/member.php...nfo&userid=247
View this thread: http://www.excelforum.com/showthread.php?threadid=27188

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable statement doobie Excel Discussion (Misc queries) 3 November 11th 09 07:42 AM
Variable in if statement Francis Hookham Excel Worksheet Functions 9 December 12th 07 02:35 PM
IF Statement Variable Jase4now Excel Discussion (Misc queries) 3 September 25th 07 10:48 PM
if than statement has too many variable repke New Users to Excel 1 May 2nd 06 02:00 PM
creating macro to ask for variable info when excel starts Flyriverside Excel Programming 1 April 7th 04 06:32 PM


All times are GMT +1. The time now is 02:04 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"