Re: SQL incorporation with Excel
From: Robin Hammond (rjNOrhSPAM_at_PLEASEnetvigator.com)
Date: 03/31/04
- Next message: monika: "urgetn ..help"
- Previous message: Charles: "Re: "Find" Macro"
- Next in thread: onedaywhen: "Re: SQL incorporation with Excel"
- Maybe reply: onedaywhen: "Re: SQL incorporation with Excel"
- Reply: onedaywhen: "Re: SQL incorporation with Excel"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 31 Mar 2004 11:16:56 +0800
Excel 2002 VBA by Bullen, Green, Bovey and Rosenberg has a fairly good
section on using ADO with Excel, and this would be your best method of
connecting to the SQL server.
As a starting point, get the latest MDAC 2.8 (and the subsequent security
patch) from MS. Set a reference to ADO 2.7 in your vb project. The code
below should give you a starting point but you'll need to work on the
connection string to find the correct way to connect. This can be
complicated but a bit of trial and error should get it.
Sub ConnectToSQL()
'requires an ADO reference in project
Dim rsInput As ADODB.Recordset
Dim cnSQL As ADODB.Connection
Dim strSQL As String
Set cnSQL = New ADODB.Connection
Set rsInput = New ADODB.Recordset
'there are lots of different ways to specify this
'The MZTools utility at www.mztools.com provides a utility that
'could help and that tests the connection as you specify it
cnSQL.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;Data Source=MyServer;" & _
"Initial File Name=c:\My Documents\My Dbs\My Database.mdb"
cnSQL.Open
strSQL = "SELECT * FROM MyView"
rsInput.Open strSQL, cnSQL, adOpenStatic, adLockBatchOptimistic, adCmdText
'optionally close the connection to disconnect the recordset
If cnSQL.State = adStateOpen Then cnSQL.Close
'if you have a valid record, this should show a positive number
MsgBox rsInput.RecordCount
End Sub
Robin Hammond
www.enhanceddatasystems.com
"gitcypher >" <<gitcypher.13y4kt@excelforum-nospam.com> wrote in message
news:gitcypher.13y4kt@excelforum-nospam.com...
> Each month, I have to create multiple invoices. I have many Excel
> workbooks, all based on the same billing template. If all goes well,
> each month, all I have to do is enter the hours worked by each
> employee, and the formulas and macros do the rest. The hours are
> entered throughout month into our time keeping system.
> The transition between our time keeping system, and our accounting
> system has been srteamlined. Our accounting system uses an SQL
> database. I would like to enable my billing template to pull employee's
> hours directly from the SQL database, removing any human interference.
>
> I know absolutely nothing about SQL... so you know what you're dealing
> with. Is there somewhere I can find a quick tutorial, or can someone
> giv e me a quick run down of the process?
>
> -Gitcypher
>
>
> ---
> Message posted from http://www.ExcelForum.com/
>
- Next message: monika: "urgetn ..help"
- Previous message: Charles: "Re: "Find" Macro"
- Next in thread: onedaywhen: "Re: SQL incorporation with Excel"
- Maybe reply: onedaywhen: "Re: SQL incorporation with Excel"
- Reply: onedaywhen: "Re: SQL incorporation with Excel"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|