[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Http post using MS-Access and VBA

Posted on 2013-11-10
7
Medium Priority
?
2,212 Views
Last Modified: 2013-11-19
I'm writing an Access application that is using a webrelay. A webrelay is a device which can switch electrical equipment on- and off and has it's own build in webserver.

I can control this device with my browser using the following URL:

http://192.168.1.200/?OUT1=ON

Now I would like to post the same URL when I click a button on a MS-Access form.

Please send me some sample code !
0
Comment
Question by:HugoMuller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 53

Expert Comment

by:Rgonzo1971
ID: 39637022
Hi,

pls try

Sub PostHttp()
Dim result As String
Dim myURL As String, postData As String
Dim HttpReq As Object
Set HttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
myURL = "http://192.168.1.200"
postData = "/?OUT1=ON"
HttpReq.Open "POST", myURL, False
HttpReq.Send (postData)
result = HttpReq.responseText
End Sub

Open in new window

regards
0
 
LVL 58
ID: 39637024
Below is some code that uses the Microsoft XML 6. Library to sent a HTTP POST request.

Jim.

                  ' Capture the CC

                  ' Set the correct URL
                  'strPostURL = "https://test.authorize.net/gateway/transact.dll"
110               strPostURL = "https://secure.authorize.net/gateway/transact.dll"
                  'strPostURL = "https://developer.authorize.net/tools/paramdump/index.php"

120               strPostSting = ""
125        strPostSting = strPostSting & "x_login=" & URLEncode(strAPILogin) & "&"
126       strPostSting = strPostSting & "x_tran_key=" & URLEncode(strTransactionKey) & "&"
                  'For debugging.
                  'strPostSting = strPostSting & "x_test_request=" & URLEncode("TRUE") & "&"
130               strPostSting = strPostSting & "x_version=" & URLEncode("3.1") & "&"
140               strPostSting = strPostSting & "x_delim_data=" & URLEncode("TRUE") & "&"
150               strPostSting = strPostSting & "x_delim_char=" & URLEncode("|") & "&"
160               strPostSting = strPostSting & "x_relay_response=" & URLEncode("FALSE") & "&"
170               strPostSting = strPostSting & "x_email_customer=" & URLEncode("FALSE") & "&"

180               strPostSting = strPostSting & "x_type=" & URLEncode("PRIOR_AUTH_CAPTURE") & "&"
190               strPostSting = strPostSting & "x_trans_id=" & URLEncode(rs!CCTransactionID) & "&"

                  ' Additional fields can be added here as outlined in the AIM integration
                  ' guide at: http://developer.authorize.net
200               strPostSting = left(strPostSting, Len(strPostSting) - 1)

                  ' We use xmlHTTP to submit the input values and record the response
                  Dim objRequest As New MSXML2.XMLHTTP
210               objRequest.Open "POST", strPostURL, False
220               objRequest.Send strPostSting
230               strPostResponse = objRequest.responseText
                  'Debug.Print strPostResponse
240               Set objRequest = Nothing

                  ' the response string is broken into an array using the specified delimiting character
250               arrResponse = Split(strPostResponse, "|", -1)

260               If arrResponse(0) = 1 Then
0
 
LVL 58
ID: 39637026
URLEncode() BTW is:

Public Function URLEncode(xxx As String) As String

    URLEncode = Replace(xxx, " ", "%20")

End Function

Jim.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 29

Expert Comment

by:IrogSinta
ID: 39637052
You can give this a try:
If you are using a toggle button on your form
Private Sub tglOnOff_AfterUpdate()
    Dim ie As Object
    
    'switch webrelay device on or off 
    Set ie = New InternetExplorer
        ie.Navigate "http://192.168.1.200/?OUT1=" & IIf(Me.Toggle15, "ON", "OFF")
        While ie.Busy = True: DoEvents: Wend
        While ie.Busy = True: DoEvents: Wend
        ie.Quit
    Set ie = Nothing
    
End Sub

Open in new window

If you are using 2 separate buttons for ON and OFF
Private Sub btnSwitchOn_Click()
    Dim ie As Object
    
     'switch webrelay device on
    Set ie = New InternetExplorer
        ie.Navigate "http://192.168.1.200/?OUT1=ON"
        While ie.Busy = True: DoEvents: Wend
        While ie.Busy = True: DoEvents: Wend
        ie.Quit
    Set ie = Nothing
    
End Sub

Private Sub btnSwitchOff_Click()
    Dim ie As Object
    
    'switch webrelay device off
    Set ie = New InternetExplorer
        ie.Navigate "http://192.168.1.200/?OUT1=OFF"
        While ie.Busy = True: DoEvents: Wend
        While ie.Busy = True: DoEvents: Wend
        ie.Quit
    Set ie = Nothing
    
End Sub

Open in new window

Ron
0
 

Author Comment

by:HugoMuller
ID: 39641824
Hi Ron,

I like simple solutions so I think you;ll get the points.
One question: why do you repeat the While Wend line. Is there a specific reason ?

Cheers, Hugo
0
 
LVL 29

Accepted Solution

by:
IrogSinta earned 1500 total points
ID: 39653346
Sorry, I just copied that from some old code I had.  I noticed back then that using a single Do Event loop somehow still allowed the code to continue even though the ie object was still busy.  Doubling it up solved the problem for us.  Since then; however, I have been using the following line of code instead and you can use it in place of the While Wend loops.

Do While ie.Busy Or ie.readyState <> READYSTATE_COMPLETE
    DoEvents
Loop

Open in new window

Ron
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39661491
Hugo,
      I'm not sure if you're aware of the criteria for grading.  You would normally assign a B grade if you had to do a good amount of extra work on your own because the answer presented was lacking.  You are also expected to provide an explanation on grades of B or C.  
     If you were still having difficulties with a provided solution, you could have followed it up here until you were satisfied.

     Here's a link explaining the Grading criteria:  http://support.experts-exchange.com/customer/portal/articles/481419-what-grade-should-i-award-?b_id=44

Ron
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 the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

656 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