Add Microsoft Access 2003 under the COM tab as a new reference
Imports Microsoft.Office.Interop.Access
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form 設計工具產生的程式碼 "
Public Sub New()
MyBase.New()
'此為 Windows Form 設計工具所需的呼叫。
InitializeComponent()
'在 InitializeComponent() 呼叫之後加入所有的初始設定
End Sub
'Form 覆寫 Dispose 以清除元件清單。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'為 Windows Form 設計工具的必要項
Private components As System.ComponentModel.IContainer
'注意: 以下為 Windows Form 設計工具所需的程序
'您可以使用 Windows Form 設計工具進行修改。
'請勿使用程式碼編輯器來修改這些程序。
Friend WithEvents Button1 As System.Windows.Forms.Button
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Button1 = New System.Windows.Forms.Button
Me.SuspendLayout()
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(112, 72)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(160, 64)
Me.Button1.TabIndex = 0
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.Button1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
PrintReport()
End Sub
Sub PrintReport()
Dim acApp As Microsoft.Office.Interop.Access.Application
Dim strDBPath As String
Const DB_PATH As String = _
"C:\Inetpub\wwwroot\NWIND.MDB"
acApp = New Microsoft.Office.Interop.Access.Application
With acApp
.OpenCurrentDatabase(DB_PATH)
' 列印「產品目錄」報表。
End With
acApp.Quit()
acApp = Nothing
MsgBox("done" & Err.Description)
End Sub
End Class