Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Location
    Greenwood, IN
    Posts
    40

    Question Unanswered: HTTPPost in VBA from Access?

    I would like to integrate an Access Database with an external API. I know it's possible to Post XML via HTTP from Visual Basic, but I'm not sure which reference to use or how the code is written.

    Does anyone have an example of making an HTTPPost from Access to a web site, api, or web service?

    Thanks!
    Doug
    Doug

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    if you know the interface (ie parameters) to the web script that handles the data then just add it to the url

    eg
    <sitename>/<Scriptname.ext>?parameter1=value&parameter2=val ue

    then force that url to run, possibly by running an instance of IE, you may even be able to access an IE runtime library

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Quote Originally Posted by healdem
    you may even be able to access an IE runtime library
    Indeed. You may find the Microsoft Web Browser activex object of interest.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  4. #4
    Join Date
    Dec 2003
    Location
    Greenwood, IN
    Posts
    40

    Reference to Microsoft XML, v5.0

    I was able to do it using this reference and the following module:
    Code:
    Public Function fcSend(strRequestXML As String)
        Dim objXMLHttp, sResponse
        Set objXMLHttp = CreateObject("MSXML2.ServerXMLHTTP")
    
        objXMLHttp.Open "POST", strAPIUrl, False
        objXMLHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        objXMLHttp.send ("qf=xml&xml=" & URLEncode(strRequestXML))
    
        If objXMLHttp.Status = 200 Then
             sResponse = objXMLHttp.responseText
        End If
        
        Set objXMLHttp = Nothing
        fcSend = sResponse
    
    End Function
    
    Function URLEncode(strData)
      Dim I, strTemp, strChar, strOut, intAsc
      
        strTemp = Trim(strData)
      
        For I = 1 To Len(strTemp)
            strChar = Mid(strTemp, I, 1)
            intAsc = Asc(strChar)
            If (intAsc >= 48 And intAsc <= 57) Or (intAsc >= 97 And intAsc <= 122) Or (intAsc >= 65 And intAsc <= 90) Then
                strOut = strOut & strChar
            Else
                strOut = strOut & "%" & Hex(intAsc)
            End If
        Next
      
    URLEncode = strOut
      
    End Function
    Doug

  5. #5
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Hmmm, haven't used ServerXMLHTTP before. It looks cleaner than using the browser object. Thanks for reporting back!
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  6. #6
    Join Date
    Dec 2003
    Location
    Greenwood, IN
    Posts
    40

    XML <> VBA

    Quote Originally Posted by Teddy
    Hmmm, haven't used ServerXMLHTTP before. It looks cleaner than using the browser object. Thanks for reporting back!
    It works fantastic with only one really bad limitation... Microsoft did a good job at integrating XML into Microsoft Office, but really only did it through the GUI, not in VBA. Too bad!

    That means I have to use the MSXML reference to also parse the XML and work with it in recordsets. Ugh!
    Doug

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •