?
Solved

How to POST data from VBA

Posted on 2006-04-07
14
Medium Priority
?
842 Views
Last Modified: 2012-05-05
Hi experts,

I'm trying to POST data from an MS Access application to a php page on my website and I just can't get it working. Has anyone a simple but working example of how to use FollowHyperlink with msoMethodPost (or any other POSTing technique)?

What I'm trying to achieve is that users can automatically log-in into the bugtracker at http://www.altiplano-ict.nl/bugs/login_page.php. The application knows the uid & password and should launch the browser when clicked on the "report a bug" button.

thanks,
0
Comment
Question by:altiplano
  • 6
  • 5
  • 3
14 Comments
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16399180
Is there not a simple querystring that is appended to this?

http://www.altiplano-ict.nl/bugs/login_page.php?UN=xxx&PW=xxx

Alternatively (and somewhat more neatly) you can use the MSXML library to make posts to an address.
There's no string limit then either (though I strongly suspect that isn't an issue for you here ;-)
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16399201
Add a reference to the MSXML library - version 3 or newer
Then something like

Dim req As New MSXML2.XMLHTTP

strAddress = "http://www.altiplano-ict.nl/bugs/login_page.php"
strPost = "UN=" & strUN & "&PW=" & strPW
With req
    .Open "POST", strAddress, False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded" '"text/xml"
    .Send strPost
End With
0
 

Author Comment

by:altiplano
ID: 16399215
>> Is there not a simple querystring that is appended to this?
>> http://www.altiplano-ict.nl/bugs/login_page.php?UN=xxx&PW=xxx

Unfortunately not. I could probably rewrite login.php as to also accept the query string, but since I didn't develop the bugtracker I'm a bit hesistant to do that. I would rather POST the data if possible.

Do you have an example using the MSXML library?

thanks,
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 34

Accepted Solution

by:
flavo earned 1000 total points
ID: 16399226
Something like this:

You need references set to:
Microsoft Internet Controls
and
Microsoft HTML Onject Library

    Dim ie As SHDocVw.InternetExplorer
    Dim h As MSHTML.HTMLDocument
   
    Set ie = New SHDocVw.InternetExplorer
   
    ie.Navigate2 "http://www.altiplano-ict.nl/bugs/login_page.php"
   
    While ie.Busy
        DoEvents
    Wend
   
   
    Set h = ie.Document
   
    h.Forms("login_form").Item("username").Value = "myUserName"
    h.Forms("login_form").Item("Password").Value = "myPassword"
    h.Forms("login_form").submit

    ie.Visible = True

Dave
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16399234
Ha - Dave's just got in there before I posted a link to that kind of example!

Oh well - there you have it :-)
0
 
LVL 34

Expert Comment

by:flavo
ID: 16399259
There weren't any posts when I started to try remember how to do it :P

Didn't know about the MSXML Lib being able to do such things.. :D
0
 

Author Comment

by:altiplano
ID: 16399354
Gosh, and people really complain about Experts-Exchange being too expensive? You just saved me a years worth of subscription fees to EE!

Thanks a 10^6, now I can go off for a relaxed lunch :-)
0
 
LVL 34

Expert Comment

by:flavo
ID: 16399368
>now I can go off for a relaxed lunch :-)
That sounds like a plan.. A pint or 3 it is :D
0
 

Author Comment

by:altiplano
ID: 16399412
>> That sounds like a plan.. A pint or 3 it is :D

Yep, 3 pints for me as well :D
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16402025
"people really complain about Experts-Exchange being too expensive" ??

They do?
Sheesh.
0
 

Author Comment

by:altiplano
ID: 16403826
> They do?
> Sheesh.

Well, not directly. But just for a laugh, do a search for "I only have points". You'll literally find hundreds of questions with some variation on "I have this very urgent an complicated question but only 25 points. Please help". If it really is this important and urgent just shell out the $10, which in my opinion is still a steal. I probably could have figured out this question myself, but it would have taken me, say, 4 hours to get it working. Now I got an excellent answer in less than 15 miutes.
0
 
LVL 44

Expert Comment

by:Leigh Purvis
ID: 16403882
Yeah - I am probably guilty of taking pity on those that report being low on points - but unless they're very poor (in which case then excellent that I've helped) then it isn't a huge ask.
I suppose the thing for those questioners to bear in mind is that the cost of EE must be kept out of mind when dealing with the experts.
We do it entirely separately of all those shenanigans.

To make the world a better place and bring the human race together as one.

(Are you drinking yet Dave - sounds like I've started :-S )
0
 

Author Comment

by:altiplano
ID: 16404007
Since I've got your attention now :) do you have any idea how I can maximize the IE window once it's opened (or do you want me to open a new question for this)?
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question