8. In the ThisAddIn_Startup method, put the insertion point in the blank line under the
last comment.
9. Add the following code:
m_oNWind = New NWindDataAccess.NWindData
m_oSheet = Me.Application.Worksheets("Sheet1")
GetData()
This code instantiates an instance of the data component, fills m_oSheet with a reference
to Sheet1 in our Excel workbook, and calls a function named GetData. Visual Studio 2005 may
bark at you because this function does not exist, yet but that??™s only temporary.
CHAPTER 9 n ACTIVEX AND .NET 336
10. Put the insertion point inside the ThisAddIn_Shutdown method.
11. Add the following line of cleanup code:
m_oNWind = Nothing
Now let??™s create the GetData method.
Getting the Data Since we added a reference to our data access project, we can refer to its
properties and methods from our add-in. The GetData method will call out to our data access
layer and fill our module-level DataSet variable. Then it will push the data out to the Excel
sheet.
1. In the ThisAddIn class module, add a new subroutine named GetData.
2. In the GetData procedure, add the following variable declarations:
Dim sDB As String = "C:\ExampleDBs\Northwind 2007.accdb"
Dim iCols As Integer
Dim i As Integer
Dim row As Integer
We??™re passing in the location of the database to the sDB String variable, and then we have
the remaining Integer variables to hold our place as we walk through the DataSet and display
our data.
3. On the first blank line below the variable declarations, type the following line of code:
Try
4.
Pages:
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309