嗨即時得到一個不正確的語法錯誤,當我運行在Outlook中下面的代碼2010 VB編輯器,香港專業教育學院串接& myNamespace.CurrentUser &「MS Outlook的VB編程
以下是代碼,這似乎是發生了什麼:
Sub ConnectSqlServer()
Dim myNamespace As Outlook.NameSpace
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=WIN-NBST3PHVFV4\ECLIPSE;" & _
"Initial Catalog=OBlive;" & _
"User ID=outlook;Password=password123;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set myNamespace = Application.GetNamespace("MAPI")
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute("INSERT INTO dbo.Submissions (CV, Consultant, Timestamp) VALUES ('1', " & myNamespace.CurrentUser & ", CURRENT_TIMESTAMP)")
' Clean up
If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
End Sub
任何幫助將是非常讚賞
它是否以硬編碼值而不是myNamespace.currentuser成功運行? –