NateO
Legend
- Joined
- Feb 17, 2002
- Messages
- 9,700
Good day fellow board members,
I'm moving up to the starting line of interfacing MS Sql servers, which I believe are housing Peoplesoft and another ERP system's data. I'm going to work with the respective companies involved, but I was doing some quick research in advance of this.
It became apparent to me that ODBC is a good option for querying in Excel, but I'd have rework the native functionality to push data. My readings have also lead me to believe that while I can use ODBC, OLEDB is MS's preferred interface, faster and more robust.
As a practice exercise, I decided to use OLEDB and ADO to interface Lotus 123 and Excel, just to get more comfortable with the methods. I came up with the following, which is working nicely today:
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> test()
<SPAN style="color:darkblue">Dim</SPAN> LotusCn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>, rsLotus <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> strSql <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Set</SPAN> LotusCn = CreateObject("ADODB.Connection")
LotusCn.<SPAN style="color:darkblue">Open</SPAN> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\temp\FILE0014.WK4;" & _
"Extended Properties=Lotus WK4;Persist Security Info=False"
<SPAN style="color:green">'Look @ Sheet a, a3:12</SPAN>
strSql = "Select * from [a:a3..a:a12]"
<SPAN style="color:darkblue">Set</SPAN> rsLotus = CreateObject("ADODB.Recordset")
<SPAN style="color:darkblue">With</SPAN> rsLotus
.<SPAN style="color:darkblue">Open</SPAN> strSql, LotusCn, 3, 3 <SPAN style="color:green">'adOpenStatic, adLockOptimistic</SPAN>
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> .EOF Then _
Sheets(1).[a1].Resize(.RecordCount).CopyFromRecordset rsLotus
.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
LotusCn.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">Set</SPAN> rsLotus = Nothing: <SPAN style="color:darkblue">Set</SPAN> LotusCn = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
But it didn't work last night! In fact, it completely killed my ability to access the file in any manner... So, I have some reservations with this...
Turns out I was on a network last night, whereas today I'm not... Could this be the reason? It's the only real change, and I know networks can bollox up Excel and automation.
Please, for both Christ's sake and mine, do not respond to this telling me to save the .wk4 as an Excel file or open the file in Excel, that is not the point of this exercise!
I simply want to get more experienced with Automation via OLEDB. Also, I don't believe the board houses code of this nature, so I wanted to provide it.
Also note, do not even bother attempting this with a .123 file, it should work with .wk3, but MS has clearly stated they don't have the drivers or interest in interfacing .123 files, it simply isn't an option from them, you might be able to buy a 3rd party driver out there, but I don't know of one, nor am I interested in find out.
Regarding the code, in ADO .EOF is the most efficient way of determining if a recordset holds any information, RecordCount is reliable in ADO (not in DAO until you move to the end of the recordset), but it's bollox slow, because of it's emphasis on accuracy. Use it for dynamic returns only (I use here simply to use it, I will have dynamic returns in the long run). Also note, I use late binding as a preference, early binding is an option and the more efficient one, late binding can prove to have less maintenance issues associated with it.
Any thoughts regarding the code? Have a nice weekend everyone!
I'm moving up to the starting line of interfacing MS Sql servers, which I believe are housing Peoplesoft and another ERP system's data. I'm going to work with the respective companies involved, but I was doing some quick research in advance of this.
It became apparent to me that ODBC is a good option for querying in Excel, but I'd have rework the native functionality to push data. My readings have also lead me to believe that while I can use ODBC, OLEDB is MS's preferred interface, faster and more robust.
As a practice exercise, I decided to use OLEDB and ADO to interface Lotus 123 and Excel, just to get more comfortable with the methods. I came up with the following, which is working nicely today:
<font face=Courier New><SPAN style="color:darkblue">Sub</SPAN> test()
<SPAN style="color:darkblue">Dim</SPAN> LotusCn <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>, rsLotus <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">Object</SPAN>
<SPAN style="color:darkblue">Dim</SPAN> strSql <SPAN style="color:darkblue">As</SPAN> <SPAN style="color:darkblue">String</SPAN>
<SPAN style="color:darkblue">Set</SPAN> LotusCn = CreateObject("ADODB.Connection")
LotusCn.<SPAN style="color:darkblue">Open</SPAN> "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\temp\FILE0014.WK4;" & _
"Extended Properties=Lotus WK4;Persist Security Info=False"
<SPAN style="color:green">'Look @ Sheet a, a3:12</SPAN>
strSql = "Select * from [a:a3..a:a12]"
<SPAN style="color:darkblue">Set</SPAN> rsLotus = CreateObject("ADODB.Recordset")
<SPAN style="color:darkblue">With</SPAN> rsLotus
.<SPAN style="color:darkblue">Open</SPAN> strSql, LotusCn, 3, 3 <SPAN style="color:green">'adOpenStatic, adLockOptimistic</SPAN>
<SPAN style="color:darkblue">If</SPAN> <SPAN style="color:darkblue">Not</SPAN> .EOF Then _
Sheets(1).[a1].Resize(.RecordCount).CopyFromRecordset rsLotus
.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">With</SPAN>
LotusCn.<SPAN style="color:darkblue">Close</SPAN>
<SPAN style="color:darkblue">Set</SPAN> rsLotus = Nothing: <SPAN style="color:darkblue">Set</SPAN> LotusCn = <SPAN style="color:darkblue">Nothing</SPAN>
<SPAN style="color:darkblue">End</SPAN> <SPAN style="color:darkblue">Sub</SPAN></FONT>
But it didn't work last night! In fact, it completely killed my ability to access the file in any manner... So, I have some reservations with this...
Turns out I was on a network last night, whereas today I'm not... Could this be the reason? It's the only real change, and I know networks can bollox up Excel and automation.
Please, for both Christ's sake and mine, do not respond to this telling me to save the .wk4 as an Excel file or open the file in Excel, that is not the point of this exercise!
I simply want to get more experienced with Automation via OLEDB. Also, I don't believe the board houses code of this nature, so I wanted to provide it.
Also note, do not even bother attempting this with a .123 file, it should work with .wk3, but MS has clearly stated they don't have the drivers or interest in interfacing .123 files, it simply isn't an option from them, you might be able to buy a 3rd party driver out there, but I don't know of one, nor am I interested in find out.
Regarding the code, in ADO .EOF is the most efficient way of determining if a recordset holds any information, RecordCount is reliable in ADO (not in DAO until you move to the end of the recordset), but it's bollox slow, because of it's emphasis on accuracy. Use it for dynamic returns only (I use here simply to use it, I will have dynamic returns in the long run). Also note, I use late binding as a preference, early binding is an option and the more efficient one, late binding can prove to have less maintenance issues associated with it.
Any thoughts regarding the code? Have a nice weekend everyone!