要開啟"c:\book1.mdb"檔,並且啟動"表單1"這個表單,程式碼如下:
(一般)
Dim a As New Access.Application
Private Sub Command1_Click()
On Error GoTo DoWith
a.OpenCurrentDatabase "c:\book1.mdb"
c = a.CurrentProject.AllForms("表單1").Name
'用一行用來檢查表單1是否存在
a.DoCmd.OpenForm "表單1"
a.Visible = True
Exit Sub
DoWith:
MsgBox "找不到表單"
End Sub
●若要開啟便啟動"資料表1",程式碼如下
(一般)
Dim a As New Access.Application
Private Sub Command1_Click()
On Error GoTo DoWith
a.OpenCurrentDatabase "c:\book1.mdb"
c = a.CurrentData.AllTables("資料表1").Name
a.DoCmd.Maximize
a.DoCmd.OpenTable "資料表1", acViewNormal
a.Visible = True '視窗放到最大
Exit Sub
DoWith:
MsgBox "找不到資料表"
End Sub