View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
onedaywhen onedaywhen is offline
external usenet poster
 
Posts: 459
Default Replacing Text In VBProject Module

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