Public gdbConn As New ADODB.Connection
Sub Main()
Dim DateSOurce As String '数据源
On Error GoTo err_Handler
'确定该程序没有被启动过
If App.PrevInstance Then
MsgBox "您已经启动过了本程序!", , "程序"
End
End If
DateSOurce = App.Path & "\DB\Transportation.mdb"
'连接数据库
gdbConn.Provider = "Microsoft.Jet.OLEDB.4.0"
gdbConn.Open DateSOurce
frmLogin.Show
Exit Sub
err_Handler:
MsgBox "数据库连接错误,请检查网络是否连通", vbOKOnly, "程序"
End
End Sub
我一般都这么写