Link to home
Start Free TrialLog in
Avatar of LianneVoelm
LianneVoelm

asked on

Use VBA to post form data and then show that data on the web page

I am posting form data to a URL using VBA from MS Access.  However, I need to end up on the URL that I'm posting the form data to and I can't seem to do this since the url ends in .php.  How do i land on the same URL that i just posted to?
       
URL = "https://websiteX.com/tastein/enterxx.php"
        Set IE = Nothing
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Navigate "about:blank"
        IE.Visible = True
       
        Set xmlhttp = CreateObject("MSXML2.XMLHTTP")
       
        xmlhttp.Open "POST", URL, False
        xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        xmlhttp.send (sPayLoad)
        Response = xmlhttp.responseText
        While IE.busy
        DoEvents
        Wend
        IE.Document.Write Response
Avatar of Norie
Norie

What code are you trying to navigate to the site with?

In the code you posted you have this,
      IE.Navigate "about:blank"

Open in new window

before the code to post data.

Have you tried using something like this, after you've posted the data?
      IE.Navigate URL 

Open in new window

Avatar of LianneVoelm

ASKER

Hi thanks for suggesting. However the URL below isn't a url that one can directly go to. Rather that page processes the form data and then displays the form for verification.  So i seem to be unable to navigate there and send or send and then navigate to there. I've tried both.  What i can do is populate that URL with the data I want to send starting with IE.Navigate "about:blank". The form displays the page with data for verification but when i try to verify, i get i referer error because (I'm told) I'm not sending it from the right place.  I need to be sending it from within the website I'm posting to.

As an additional resource there is a sample form that was provided to me that is has a single button on it and the code behind the button does in html from that form what i need to accomplish hopefully using VBA from ms Access.

It's possible i'm going about this all wrong. Thanks for any help!  Lianne

<form method="POST" action="https://website.com/tastein/enter0285927.php">  
<input type="hidden" name="SOL_ISN" value="123">  
<input type="hidden" name="SOL_title" value="Sample string">  
<input type="hidden" name="SOL_exporter" value="123">  
<input type="submit" name="proceed" value="Proceed with Staffing">  
</form>
Lianne

As far as I can see this part of the posted code has nothing to do with the later code you are using to post data to the site.
        Set IE = Nothing
        Set IE = CreateObject("InternetExplorer.Application")
        IE.Navigate "about:blank"
        IE.Visible = True

Open in new window


All that code is doing is opening an instance of IE and navigating to a blank page.
Maybe this isn't the right way to do this, but at the end of my code i'm writing the Reponse to IE using IE.Document.Write Response as a way to see what i have sent.  That is why i have those IE lines you referenced.   Otherwise, how would i see the url with the data i have sent?   Thanks!
     
xmlhttp.Open "POST", URL, False
        xmlhttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        xmlhttp.send (sPayLoad)
        Response = xmlhttp.responseText
        While IE.busy
        DoEvents
        Wend
        IE.Document.Write Response
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.