Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default problem on passing value

I have a problem regarding passing parameter from excel spreadsheet to a
backend sql
database to refresh data.

For example, I already add a text box in an excel spreadsheet to let me
pass in whatever production year I needed e.g. 1998, 1999, 2000, 2001,
....... etc. as a parameter.
but without success. Can anyone suggest a code from excel text box sending
any of the
year parameter to the database to refresh the data in excel according to the
year entered
by the user.
Sample of my code is shown below.


' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT * FROM STOCKMASTER WHERE PRODUCTION_YEAR = 2002;"

.Open Source:=Src, ActiveConnection:=Connect
' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next

' Write the recordset
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With
Set Recordset = Nothing
Connect.Close
Set Connect = Nothing

Can someone help me to solve this problem and any solution provided will be
highly appreciated.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default problem on passing value

If I understand you correctly... Where you currently have a hard coded year
in your SQL statement you want to use the value of a cell...

Src = "SELECT * FROM STOCKMASTER WHERE PRODUCTION_YEAR = " &
sheets("Sheet1").range("A1") & ";"

HTH

"alvin" wrote:

I have a problem regarding passing parameter from excel spreadsheet to a
backend sql
database to refresh data.

For example, I already add a text box in an excel spreadsheet to let me
pass in whatever production year I needed e.g. 1998, 1999, 2000, 2001,
....... etc. as a parameter.
but without success. Can anyone suggest a code from excel text box sending
any of the
year parameter to the database to refresh the data in excel according to the
year entered
by the user.
Sample of my code is shown below.


' Create RecordSet
Set Recordset = New ADODB.Recordset
With Recordset
' Filter
Src = "SELECT * FROM STOCKMASTER WHERE PRODUCTION_YEAR = 2002;"

.Open Source:=Src, ActiveConnection:=Connect
' Write the field names
For Col = 0 To Recordset.Fields.Count - 1
Range("A1").Offset(0, Col).Value = Recordset.Fields(Col).Name
Next

' Write the recordset
Range("A1").Offset(1, 0).CopyFromRecordset Recordset
End With
Set Recordset = Nothing
Connect.Close
Set Connect = Nothing

Can someone help me to solve this problem and any solution provided will be
highly appreciated.





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
formula for % passing RKing Excel Worksheet Functions 2 August 30th 07 03:32 PM
Excel VBA - Problem calculating and passing values to another worksheet DanielCox Excel Programming 1 August 31st 04 12:36 PM
Problem passing by reference Ted[_8_] Excel Programming 10 February 23rd 04 07:27 PM
Passing a Range to a Function problem (still not working) Rocky McKinley Excel Programming 7 January 8th 04 12:53 AM
Passing a Range to a Function Problem Rocky McKinley Excel Programming 4 January 7th 04 02:00 AM


All times are GMT +1. The time now is 04:39 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"