Macro

A

augam

Is there any way that I can choose what data I want from a SQL database
by using a Macro

eg I would like to have a set of data based on date selection, can this
be added as a macro in the Excel spreadsheet.

In anticipation
 
W

William Ryan

Sure, all you need to do is dynamically create your SQL statement...Here's a
sample of it (Just modify the SQL Statement, specify your own server and it
should run.)

With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DRIVER=SQL Server;SERVER=AUG-SQLSRV;UID=wryan;APP=Microsoft
Office 11 Beta;WSID=BILLRYAN;DATABASE=JobTracking;Trusted_Connectio" _
), Array("n=Yes")), Destination:=Range("A1"))
.CommandText = Array( _
"SELECT Tbl_Log_Viewers.UserName, Tbl_Log_Viewers.Password,
Tbl_Log_Viewers.Department, Tbl_Log_Viewers.Id, Tbl_Log_Viewers.FacilityID,
Tbl_Log_Viewers.SQL_Statement, Tbl_Log_Viewers.First_Name, Tbl_Lo" _
, _
"g_Viewers.Last_Name, Tbl_Log_Viewers.Password_Hint,
Tbl_Log_Viewers.Email_Address, Tbl_Log_Viewers.Time_Logged,
Tbl_Log_Viewers.Telephone, Tbl_Log_Viewers.Fax, Tbl_Log_Viewers.Admin,
Tbl_Log_Viewers.T" _
, "ransCompany" & Chr(13) & "" & Chr(10) & "FROM
JobTracking.dbo.Tbl_Log_Viewers Tbl_Log_Viewers")
End With
augam said:
Is there any way that I can choose what data I want from a SQL database
by using a Macro

eg I would like to have a set of data based on date selection, can this
be added as a macro in the Excel spreadsheet.

In anticipation
creating financial statements
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top