Outlook VBA Passing form variables to XMLHTTP

时间:2015-07-31 20:53:44

标签: vba outlook xmlhttprequest

I'm trying to pass textbox values from an Outlook userform to an asmx web service. I've done this successfully with PHP but now need to do so with VBA. Currently the form does absolutely nothing on submit. I believe something is wrong with what or how I'm passing to the send method. Any suggestions how I can get this to work?

CliAcctNo = TicketCreateForm1.CliAcctNo.Value
ContactName = TicketCreateForm1.ContactName.Value
ContactNum = TicketCreateForm1.ContactNum.Value
Ext = TicketCreateForm1.Ext.Value
Email = TicketCreateForm1.Email.Value
TicketTitle = TicketCreateForm1.TicketTitle.Value
TicketDesc = TicketCreateForm1.Desc.Value

'DataToPost = ("cliacctno=44121&pname=John&pnum=404-223-9655&ext=0&emailaddress=john@noemail.com&tickettitle=test from vab&ticketdetails=test line item vba")
'objEvn.Parameters.Create "Test", "Test"
DataToPost = ("CliAcctNo&ContactName&ContactNum&Ext&Email&TicketTitle&TicketDesc")




Set objHttp = New MSXML2.XMLHTTP
'Set objHttp = New MSXML2.XMLHTTPRequest
objHttp.Open "POST", "http://localhost/test/test.asmx"
objHttp.setRequestHeader "Content-Type", "text/xml"
'objHttp.setRequestHeader "SOAPAction", "CreateTicket"
objHttp.setRequestHeader "SOAPAction", "tempri.org/CreateTicket"
objHttp.Send (DataToPost)

1 个答案:

答案 0 :(得分:0)

在您发布的代码中,您正在向Web服务发送一个固定字符串:您需要以某种方式在其中包含您的参数 -

CliAcctNo = TicketCreateForm1.CliAcctNo.Value
ContactName = TicketCreateForm1.ContactName.Value
ContactNum = TicketCreateForm1.ContactNum.Value
Ext = TicketCreateForm1.Ext.Value
Email = TicketCreateForm1.Email.Value
TicketTitle = TicketCreateForm1.TicketTitle.Value
TicketDesc = TicketCreateForm1.Desc.Value

'DataToPost = ("cliacctno=44121&pname=John&pnum=404-223-9655&ext=0&emailaddress=john@noemail.com&tickettitle=test from vab&ticketdetails=test line item vba")


 DataToPost = "cliacctno=" & CliAcctNo & _
             "pname=" & ContactName & _
             "pnum=" & ContactNum & _
             "ext=" & Ext & _
             "emailaddress=" & Email & _
             "tickettitle=" & TicketTitle & _
             "ticketdetails=" & TicketDesc