2014-03-31 71 views
0

嗨即時得到一個不正確的語法錯誤,當我運行在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 

任何幫助將是非常讚賞

+0

它是否以硬編碼值而不是myNamespace.currentuser成功運行? –

回答

0

您需要引用值:

...VALUES ('1', '" & myNamespace.CurrentUser & "', CURRENT_TIMESTAMP... 
+0

謝謝這工作 – linux007

0

Namespace.CurrentUser返回收件人對象。你的意思是myNamespace.CurrentUser。 名稱