Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default How can I get VBA to create a table or run a query in MS SQL?

I use Excel quite a bit using ODBC connections with Access (where queries are
stored) that ultimately ends up querying a MS SQL database -- What I would
like to do is eliminate the "middle guy" in not using Access in between and
would also like to create dynamic queries within Excel's vba environment to
query the MS SQL database directly -- I would also like to create dynamic
queries in vba -- I can handle the dynamic query part of creating a sql query
-- I just don't know how to handle sending the query directly to MS SQL from
VBA.

Any ideas?

I have been successful in creating select queries from a vba environment --
its just trying to do make table queries withing vba --
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,081
Default How can I get VBA to create a table or run a query in MS SQL?

MSDN has any number of articles about how to do this. Here's one of them

http://support.microsoft.com/kb/278973

"Rubble" wrote:

I use Excel quite a bit using ODBC connections with Access (where queries are
stored) that ultimately ends up querying a MS SQL database -- What I would
like to do is eliminate the "middle guy" in not using Access in between and
would also like to create dynamic queries within Excel's vba environment to
query the MS SQL database directly -- I would also like to create dynamic
queries in vba -- I can handle the dynamic query part of creating a sql query
-- I just don't know how to handle sending the query directly to MS SQL from
VBA.

Any ideas?

I have been successful in creating select queries from a vba environment --
its just trying to do make table queries withing vba --

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,081
Default How can I get VBA to create a table or run a query in MS SQL?

Probably a better article to start

http://office.microsoft.com/en-us/as...548031033.aspx

"Rubble" wrote:

I use Excel quite a bit using ODBC connections with Access (where queries are
stored) that ultimately ends up querying a MS SQL database -- What I would
like to do is eliminate the "middle guy" in not using Access in between and
would also like to create dynamic queries within Excel's vba environment to
query the MS SQL database directly -- I would also like to create dynamic
queries in vba -- I can handle the dynamic query part of creating a sql query
-- I just don't know how to handle sending the query directly to MS SQL from
VBA.

Any ideas?

I have been successful in creating select queries from a vba environment --
its just trying to do make table queries withing vba --

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default How can I get VBA to create a table or run a query in MS SQL?

Thank you for your replies -- it looks like after a quick look at the two
articles that both address how to pull data into Excel from an external
database -- do either articles indirectly address how to write data from
Excel to the MS SQL database? I am thinking I may have to just write a
procedure that saves a csv file to my hard drive in vba and then create
something on the MS SQL side to import the file.

Once again -- thank you for your help on this !!


"Duke Carey" wrote:

Probably a better article to start

http://office.microsoft.com/en-us/as...548031033.aspx

"Rubble" wrote:

I use Excel quite a bit using ODBC connections with Access (where queries are
stored) that ultimately ends up querying a MS SQL database -- What I would
like to do is eliminate the "middle guy" in not using Access in between and
would also like to create dynamic queries within Excel's vba environment to
query the MS SQL database directly -- I would also like to create dynamic
queries in vba -- I can handle the dynamic query part of creating a sql query
-- I just don't know how to handle sending the query directly to MS SQL from
VBA.

Any ideas?

I have been successful in creating select queries from a vba environment --
its just trying to do make table queries withing vba --

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default How can I get VBA to create a table or run a query in MS SQL?

K - I think I got it now -- I use

strQuery = "SELECT * FROM [Sheet1$A1:B10]"

in order to get the information that I want to update into MS SQL -- and
then after identifying the SQL database and all I use something like the
following :

sSQL = "INSERT INTO Contacts (FirstName, LastName) " & _
" VALUES (strQuery)"
oConn.Execute sSQL

Is that at least going down the correct road?

Thanks Again



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,081
Default How can I get VBA to create a table or run a query in MS SQL?

That's the path I'd go down.

"Rubble" wrote:

K - I think I got it now -- I use

strQuery = "SELECT * FROM [Sheet1$A1:B10]"

in order to get the information that I want to update into MS SQL -- and
then after identifying the SQL database and all I use something like the
following :

sSQL = "INSERT INTO Contacts (FirstName, LastName) " & _
" VALUES (strQuery)"
oConn.Execute sSQL

Is that at least going down the correct road?

Thanks Again

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default How can I get VBA to create a table or run a query in MS SQL?

Thank you

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
How to create a Web query in Excel? Eric Excel Discussion (Misc queries) 0 March 2nd 08 01:26 PM
how to create a web query TUNGANA KURMA RAJU Excel Discussion (Misc queries) 1 February 7th 07 09:05 AM
VB way to remove the query from a Query Table? Toby Erkson[_3_] Excel Programming 4 October 29th 04 03:16 PM
Linking a table in Access to a table in Excel using MS Query Diana[_5_] Excel Programming 1 January 16th 04 09:43 PM
create a source table from a special pasted value dynamic crossed table Tom Ogilvy Excel Programming 0 September 29th 03 08:59 PM


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