作者 主題: asp .net link to access mdb codes  (閱讀 7248 次)

0 會員 與 1 訪客 正在閱讀本文。

小徒兒

  • 鑽研的研究生
  • *****
  • 文章數: 622
    • 檢視個人資料
asp .net link to access mdb codes
« 於: 2011-03-30 14:48 »
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
« 上次編輯: 2011-03-30 14:50 由 小徒兒 »

小徒兒

  • 鑽研的研究生
  • *****
  • 文章數: 622
    • 檢視個人資料
回覆: asp .net link to access mdb codes -> Compare VBA
« 回覆 #1 於: 2011-03-30 14:56 »
' Include the following in Declarations section of module.
Dim appAccess As Access.Application

Sub DisplayForm()

    Dim strDB as String

    ' Initialize string to database path.
    Const strConPathToSamples = "C:\Program " _
        & "Files\Microsoft Office\Office11\Samples\"

    strDB = strConPathToSamples & "Northwind.mdb"
    ' Create new instance of Microsoft Access.
    Set appAccess = _
        CreateObject("Access.Application")
    ' Open database in Microsoft Access window.
    appAccess.OpenCurrentDatabase strDB
    ' Open Orders form.
    appAccess.DoCmd.OpenForm "Orders"
End Sub