---
# System prepended metadata

title: 'VBA connect sql express database '
tags: [ifix]

---

---
title: 'VBA connect sql express database '
disqus: hackmd
---
###### tags: `ifix`

**VBA 連線 sql express database **
```
Private Sub connect()
Dim objRec
Dim objConn
Dim cmdStrings

Set objRec = CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")

objConn.ConnectionString = "Provider="提供者";Server="資料庫IP";Initial Catalog="資料庫名稱";User Id="使用者名稱";Password="密碼"" 
'Provider 提供者 ,Server 資料庫IP,Initial Catalog 資料庫名稱,User Id 使用者名稱;Password 密碼"

MsgBox (objConn.ConnectionString)

objConn.Open
MsgBox ("成功")

cmdString = "sql語法"
MsgBox (cmdString)

Set objRec = objConn.Execute(cmdString)
objConn.Close

End Sub
```