#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default SQL from VB

Hi,
I need to do function or sub, which is able to edit a SELECT in MS QUERY.
For example:

MS QUERY SQL:
select * from dba.company where name='ABC'

EXCEL VB:
function do_sql(X)
select * from dba.company where name=X
end function

What is the right way to do this. Is it possible to use SQL in VB?

Thanx, kamil


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default SQL from VB

Yes it is. The best way to get started is to turn on the macro recorder, run
your MS Query, then edit the macro to your needs. You could post back if you
have any specific problems then.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"kamil b." wrote in message
...
Hi,
I need to do function or sub, which is able to edit a SELECT in MS QUERY.
For example:

MS QUERY SQL:
select * from dba.company where name='ABC'

EXCEL VB:
function do_sql(X)
select * from dba.company where name=X
end function

What is the right way to do this. Is it possible to use SQL in VB?

Thanx, kamil




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default SQL from VB

First, you could do this by setting up a parameter in MSQuery linked to your
workbook; if you do not know how to do that then check the Help in MSQuery on
Parameters.

But if you need to do this in code, it is really quite easy. If you have
the query set up already for a particular set of data, the SQL used will be
in the QueryTable.CommandText property. You can modify it easily with code
then refresh your query:

With Worksheets("SheetName").QueryTables(1)
.CommandText = Replace(.CommandText, "'ABC'", "'X'")
.Refresh
End With
--
- K Dales


"kamil b." wrote:

Hi,
I need to do function or sub, which is able to edit a SELECT in MS QUERY.
For example:

MS QUERY SQL:
select * from dba.company where name='ABC'

EXCEL VB:
function do_sql(X)
select * from dba.company where name=X
end function

What is the right way to do this. Is it possible to use SQL in VB?

Thanx, kamil



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



All times are GMT +1. The time now is 11:42 AM.

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"