How to send a message from MS Access using twilio?

2019-07-11 23:58发布

I have done a lot of research but I have found nothing. Has anyways already done this? Any examples?

I want to send a message using a button in a form so it should call a vba code and use some information in the same form to send the message. Any ideas would be great!!

I'm using Access 2010

1条回答
做个烂人
2楼-- · 2019-07-12 00:29

Twilio evangelist here.

The short answer is you need to POST to the Twilio REST API using VBA.

Here is a bit of sample code that shows how to do this using XMLHTTP:

Public Function GET_MESGS()
    Dim Message As String
    Dim Number As String

    On Error GoTo Error_Handler

    Const NOINTERNETAVAILABLE = -2147012889

    Dim objSvrHTTP As XMLHTTP
    Dim varProjectID, varCatID, strT As String

    Set objSvrHTTP = New XMLHTTP
    objSvrHTTP.Open "POST", "https://api.twilio.com/2010-04-01/Accounts/[YOUR_ACCOUNT_SID]/SMS/", False, "[YOUR_ACCOUNT_SID]", "[YOUR_AUTH_TOKEN]"

    objSvrHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    objSvrHTTP.send "message=" & Message & "&from=15555555555&to=" & Number

    debug.print objSvrHTTP.responseText

    ‘If objSvrHTTP.status = 201 Then
    ‘txtXML = objSvrHTTP.responseText
    ‘MsgBox "Sent"
    ElseIf objSvrHTTP.status = 400 Then
        MsgBox "Failed with error# " & _
            objSvrHTTP.status & _
            " " & objSvrHTTP.statusText & vbCrLf & vbCrLf
    ElseIf objSvrHTTP.status = 401 Then
        MsgBox "Failed with error# " & objSvrHTTP.status & _
            " " & objSvrHTTP.statusText & vbCrLf & vbCrLf
    Else
        MsgBox "Failed with error# " & objSvrHTTP.status & _
            " " & objSvrHTTP.statusText
    End If

Exit_Procedure:

    On Error Resume Next

    Set objSvrHTTP = Nothing

Exit Function

Error_Handler:

    Select Case Err.Number

        Case NOINTERNETAVAILABLE
            MsgBox "Connection to the internet cannot be made or " & _
                "Twilio website address is wrong"

        Case Else
            MsgBox "Error: " & Err.Number & "; Description: " & Err.Description

            Resume Exit_Procedure

        Resume

    End Select

End Function

Devin

查看更多
登录 后发表回答