M
Matt Dunphy
Having delved into VBA for the first time this week, I've made some
pretty good progress in writing a small app that dumps monthly actuals
for assignments into an Excel spreadsheet, but have come to a
roadblock. Now that I can generate this report for an open project, I
need to run it on every Project on the server. I figure I can do this
by using a couple of simple SQL Statements to count and pull the
project names from the MSP_Projects table.
But I can't get VBA talking to the SQL server. I know I'm missing
something very fundamental and easy, but my background in this
development environment is nonexistant. I've figured enough out so far
between the SDK and some helpful posts here, and if someone could help
me clear this little hurdle, that'd be fantastic.
I've plagiarized most of this little subroutine from this very group:
******************************
Const strConn As String = "Provider=MSDASQL.1; blah blah blah"
Dim strSQL1, strSQL2 As String
Dim cn As New Connection
Dim rs As New Recordset
Dim fld As Field
cn.Open strConn
strSQL1 = "SELECT count(PROJ_ID) AS ProjectCount FROM MSP_Projects"
strSQL2 = "SELECT proj_Name FROM MSP_Projects"
rs.Open strSQL1, cn
For Each fld In rs.Fields
Debug.Print fld.Name, fld.Value
Next
******************
I've set up a tested-and-working ODBC connection, given my account
permissions on the SQL server, created a UDL file (from which I grabbed
the connection string), and I was rearing to go, but VBA doesn't really
understand what Connection, Recordset, and Field are. I figure I must
be missing some kind of 'include' that defines these items. I've
racked my brain (and Google's coffers) for an answer, and I've read
something about Referencing an OLEDB DLL, but haven't found anything
that makes this work.
What, precisely, am I missing? If you can throw me a key word to
further research, I'll happily take that, if you give me straight-up
code, that's cool to. All I need is to fill a VBA array with all the
Project names on the server.
pretty good progress in writing a small app that dumps monthly actuals
for assignments into an Excel spreadsheet, but have come to a
roadblock. Now that I can generate this report for an open project, I
need to run it on every Project on the server. I figure I can do this
by using a couple of simple SQL Statements to count and pull the
project names from the MSP_Projects table.
But I can't get VBA talking to the SQL server. I know I'm missing
something very fundamental and easy, but my background in this
development environment is nonexistant. I've figured enough out so far
between the SDK and some helpful posts here, and if someone could help
me clear this little hurdle, that'd be fantastic.
I've plagiarized most of this little subroutine from this very group:
******************************
Const strConn As String = "Provider=MSDASQL.1; blah blah blah"
Dim strSQL1, strSQL2 As String
Dim cn As New Connection
Dim rs As New Recordset
Dim fld As Field
cn.Open strConn
strSQL1 = "SELECT count(PROJ_ID) AS ProjectCount FROM MSP_Projects"
strSQL2 = "SELECT proj_Name FROM MSP_Projects"
rs.Open strSQL1, cn
For Each fld In rs.Fields
Debug.Print fld.Name, fld.Value
Next
******************
I've set up a tested-and-working ODBC connection, given my account
permissions on the SQL server, created a UDL file (from which I grabbed
the connection string), and I was rearing to go, but VBA doesn't really
understand what Connection, Recordset, and Field are. I figure I must
be missing some kind of 'include' that defines these items. I've
racked my brain (and Google's coffers) for an answer, and I've read
something about Referencing an OLEDB DLL, but haven't found anything
that makes this work.
What, precisely, am I missing? If you can throw me a key word to
further research, I'll happily take that, if you give me straight-up
code, that's cool to. All I need is to fill a VBA array with all the
Project names on the server.