Option Compare Database
'Used for Text Messaging interface
Global Const strClickatellURL = "http://api.clickatell.com/http/sendmsg?"
Global Const strAPI_ID = "api_id=****" 'replace <api_id> with your API ID
Global Const strClickatell_User = "&user=****" 'replace <UserID> with your clickatell userid
Global Const strClickatell_Pass = "&password=****" 'replace <password> with your password
Global Const strClickatell_From = "&from=447*64**38**" 'Replace <whofrom> with name of co etc, 11 chars max
Public Sub SendText1(strMessage As String, strNumber As String)
'Function Name: SendText
'Purpose: This function formats a string (strMessage) ready for sending via SMS, and then sends it
'by using a HTTP post (OpenURL).
'
'This service requires an active account with Clickatell.com, with active credits.
'You must pass through the API ID, Clickatell Username AND Password for it to work.
'Full details are available on Clickatell.com
'
'Function created by Adam Taylor - adaytay on UA, July 2006.
'If Len(strMessage) = 0 Then Exit Sub
' If Len(strMessage) > 160 Then
' MsgBox "Message is too long - maximum 160 characters (including spaces)" & vbCrLf _
' & "Your message is currently " & Len(strMessage) & " characters", vbOKOnly + vbExclamation, _
' "Too long!"
' Exit Sub
'End If
Dim strBody As String, strFooter As String
'I liked to add a footer to the text message here as we used this to text clients
'strFooter = Replace("*Job order", " ", "+")
strFooter = Replace("-" & [Forms]![frmTimerecordEdit]![txtUser], " ", "+")
strBody = strClickatellURL & strAPI_ID & strClickatell_User & strClickatell_Pass & strClickatell_From
'Modify the format of the message and check the number is in the right format...
strMessage = Replace(strMessage, " ", "+")
strMessage = Replace(strMessage, "&", "and")
strNumber = Replace(strNumber, " ", "")
If Left(strNumber, 1) = "0" Then strNumber = "44" & Mid(strNumber, 2, 99)
'All built and ready... now get the message ready to send..
strBody = strBody & "&to=" & strNumber & "&text=" & strMessage & strFooter
DoEvents
If Not OpenURL(strBody) Then
MsgBox "Sorry, there was a problem when attempting to send the message", vbOKOnly + vbInformation, "Could not connect to internet"
End If
'Resume
End Sub
Public Function OpenURL(strURL As String) As Boolean
'This function will open a specified URL as a hidden application, then once the page has loaded,
'it will immediately close the page (used to send message to internet)
'Originally by Oli S (Freakazeud), tweaked by Adam Taylor, adaytay@UA, 21 April 2006
On Error GoTo SendFailure
Dim Shell, IE
Set Shell = CreateObject("Wscript.Shell")
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = False
.Silent = True
.Navigate (strURL)
While .Busy
Wend
End With
IE.Quit
Set IE = Nothing
Set Shell = Nothing
DoEvents
OpenURL = True
Exit Function
SendFailure:
OpenURL = False
End Function