Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi is it possible to use vba code to change text in a
module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Charles
why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Rather than create dynamic SQL (which is a bit evil), create a 'stored
procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} -- "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
O.K. I agree this is the way in respect to performance. But if the OP
does not want to struggle with Stored Procedures dynamic SQL would do :-) -- Regards Frank Kabel Frankfurt, Germany onedaywhen wrote: Rather than create dynamic SQL (which is a bit evil), create a 'stored procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
What you suggested is not dynamic SQL, but dynamically constructing an SQL
string. Dynamic SQL is something completely different and is evil. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Frank Kabel" wrote in message ... O.K. I agree this is the way in respect to performance. But if the OP does not want to struggle with Stored Procedures dynamic SQL would do :-) -- Regards Frank Kabel Frankfurt, Germany onedaywhen wrote: Rather than create dynamic SQL (which is a bit evil), create a 'stored procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi Bob,
I admit I may be incorrectly lumping 'constructing a sql string on the fly' in with dynamic SQL (I was hedging by say 'a bit evil'!) Could clarify your understanding of the difference? A quick google search turned up this definition, which seems typical: 'Dynamic SQL means SQL statements are not prewritten into your programs; instead, they are constructed at run time as character strings and then passed to the SQL engine for execution.' Jamie. -- "Bob Phillips" wrote in message ... What you suggested is not dynamic SQL, but dynamically constructing an SQL string. Dynamic SQL is something completely different and is evil. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Frank Kabel" wrote in message ... O.K. I agree this is the way in respect to performance. But if the OP does not want to struggle with Stored Procedures dynamic SQL would do :-) -- Regards Frank Kabel Frankfurt, Germany onedaywhen wrote: Rather than create dynamic SQL (which is a bit evil), create a 'stored procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Frank, Funny, I though the OP *is* struggling with dynamic SQL ;-)
Actually, I was trying to simply things for the OP. Creating a stored procedure can be as simple as executing a CREATE PROCEDURE statement, and hopefully mine is a useful template. Using a stored procedure to me seems analogous with using a VBA function with arguments i.e. encapsulates functionality and hides complexity from the user; they pass in the parameters and get back some values. -- "Frank Kabel" wrote in message ... O.K. I agree this is the way in respect to performance. But if the OP does not want to struggle with Stored Procedures dynamic SQL would do :-) -- Regards Frank Kabel Frankfurt, Germany onedaywhen wrote: Rather than create dynamic SQL (which is a bit evil), create a 'stored procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jamie,
Just seen this after replying to your other post. I think we are violently agreeing here<vbg Bob "onedaywhen" wrote in message om... Frank, Funny, I though the OP *is* struggling with dynamic SQL ;-) Actually, I was trying to simply things for the OP. Creating a stored procedure can be as simple as executing a CREATE PROCEDURE statement, and hopefully mine is a useful template. Using a stored procedure to me seems analogous with using a VBA function with arguments i.e. encapsulates functionality and hides complexity from the user; they pass in the parameters and get back some values. -- "Frank Kabel" wrote in message ... O.K. I agree this is the way in respect to performance. But if the OP does not want to struggle with Stored Procedures dynamic SQL would do :-) -- Regards Frank Kabel Frankfurt, Germany onedaywhen wrote: Rather than create dynamic SQL (which is a bit evil), create a 'stored procedure' in your database and pass the values from your combo boxes to the procedure as input parameters. Here's an example which takes two dates as parameters: CREATE PROCEDURE MyStoredProc ( start_date DATETIME, end_date DATETIME ) AS SELECT RefID, DateEffective, Earnings FROM EarningsHistory WHERE DateEffective BETWEEN start_date AND end_date; If you are using ADO, use a command object to create the parameters and invoke the stored proc. If you are using MS Query, here's what should appear in the SQL window to run the above procedure with parameters: {Call MyStoredProc('01 JAN 2001', '01 JAN 2004')} "Frank Kabel" wrote in message ... Hi Charles why don't you just build the SQL string (using text concatenation) as pass this string to the module / SQL Querey? -- Regards Frank Kabel Frankfurt, Germany Charles wrote: Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It's possible. Visit this very handy site...
http://j-walk.com/ss/excel/tips/tip96.htm -----Original Message----- Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles . |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Charles,
Ignore this advice and follow Frank's suggestion. It is more direct, simpler, and more appropriate. -- HTH Bob Phillips ... looking out across Poole Harbour to the Purbecks (remove nothere from the email address if mailing direct) "Serkan" wrote in message ... It's possible. Visit this very handy site... http://j-walk.com/ss/excel/tips/tip96.htm -----Original Message----- Hi is it possible to use vba code to change text in a module at run time I am using Excel XP, it will be in the same file. if any body can guide in the right direction it will much appreciated. I am trying to write a sql statment to query a table in MSAccess but the user can select from three Comboboxes, I wanted to add the Where string at run time to the code. TIA Charles . |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro - Fixed text code needs replacing with variable text | Excel Discussion (Misc queries) | |||
replacing text in all cells with existing text plus something | Excel Discussion (Misc queries) | |||
Documentation for VBProject | Excel Programming | |||
VBProject events? | Excel Programming | |||
VBProject events? | Excel Programming |