LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Querying a SQL Server Database

SQL Server 2000. Excel 2003. I know how to set an Excel sheet to query my
SQL Server database table(s) and populate the sheet cells. This works for
some of my needs. But in general I would like to be able to do a query and
have the results go to a record set, that I can then programmatically
manipulate. Can anyone help me with some sample VBA code that populates a
record set from a SQL Server database? Thanks and God bless for any help
provided.

What I am using now to populate the Excel sheet is:

With ThisWorkbook.Sheets("Project
Definitions").QueryTables.Add(Connection:= _

"ODBC;DSN=AFNINI_1;Description=Good_News_FE;UID=FE open7;;APP=Microsoft Office
2003;WSID=DOUG;DATABASE=Good_News_FE" _
, Destination:=Range("J1"))
.CommandText = "SELECT GL7PROJECTS.PROJECTID,
GL7PROJECTS.DESCRIPTION, GL7PROJECTS.STARTDATE, TABLEENTRIES.DESCRIPTION FROM
(GL7PROJECTS LEFT JOIN GL7PROJECTATTRIBUTES ON GL7PROJECTS.GL7PROJECTSID =
GL7PROJECTATTRIBUTES.PARENTID) LEFT JOIN TABLEENTRIES ON
GL7PROJECTATTRIBUTES.TABLEENTRIESID = TABLEENTRIES.TABLEENTRIESID ORDER BY
GL7PROJECTS.PROJECTID;"
.Name = "Project Attributes Query"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
End With

--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org
 
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
Querying Large Database RussellT Excel Discussion (Misc queries) 0 November 2nd 09 07:46 PM
Querying SQL Server from Excel James C. Excel Discussion (Misc queries) 1 January 16th 07 05:51 PM
Database access & querying Steve[_78_] Excel Programming 7 September 12th 05 02:21 PM
Querying Access Database Edgar Thoemmes Excel Worksheet Functions 1 December 15th 04 01:58 PM
Querying a database for values in each row Stephen Goldfinger Excel Programming 13 December 19th 03 01:25 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"