UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Do While ... Loop Code To Check, Access 2010    
 
   
mfamunir
post Jun 21 2019, 07:53 AM
Post#1



Posts: 11
Joined: 11-June 18



Hi,
I'm trying to send one to one bulk message (Each and every number contains individual message) from my MS Access database using Do While ...Loop method. To do this I've written the following code. On experimental basis, I wanted to send three different ‍SMS to three different numbers. But unfortunately the system is sending the first message repeatedly to the first number only. Is there any missing in my code or it's the fault of the sms service provider?


CODE
Private Sub cmdOneToOneBulk_Click()
Dim objXML As Object
Dim UName As String
Dim PWD As String
Dim URL As String
    
UName = "username"
PWD = "password#"

If Me.Dirty Then Me.Dirty = False
    With Me.RecordsetClone
      .MoveFirst
      Do While Not .EOF

URL = "http://example.com/api/v1/sendSms?"
                Set objXML = CreateObject("Microsoft.XMLHTTP")
                    objXML.Open "POST", URL, False
                objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        objXML.send "username=" + UName + "&password=" + PWD + "&number=" + MobileNo + "&sms_content=" + SMS_Content

.Edit
        .Fields("DeliveryStatus") = objXML.responseText
        .Update

        .MoveNext
      Loop
    End With
    
End Sub


Regards,
Go to the top of the page
 
DanielPineault
post Jun 21 2019, 08:35 AM
Post#2


UtterAccess VIP
Posts: 6,765
Joined: 30-June 11



I'm thinking you'd need to do something more along the lines of
CODE
Private Sub cmdOneToOneBulk_Click()
    Dim rs                    As DAO.Recordset
    Dim objXML                As Object
    Dim UName                 As String
    Dim PWD                   As String
    Const URL = "http://example.com/api/v1/sendSms?"

    UName = "username" 'This could be a Const as well
    PWD = "password#"  'This could be a Const as well

    Set objXML = CreateObject("Microsoft.XMLHTTP")    'Only create it once

    If Me.Dirty Then Me.Dirty = False
    Set rs = Me.Recordset
    With rs
        If .RecordCount <> 0 Then
            .MoveFirst
            Do While Not .EOF
                objXML.Open "POST", URL, False
                objXML.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
                objXML.send "username=" & UName & "&password=" & PWD & "&number=" & ![MobileNo] & "&sms_content=" & ![SMS_Content]

                .Edit
                ![DeliveryStatus] = objXML.responseText
                .Update

                .MoveNext
            Loop
        End If
    End With

    rs.Close
    Set rs = Nothing
    Set objXML = Nothing
End Sub


Don't forget error handling!

--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 
mfamunir
post Jun 22 2019, 12:09 AM
Post#3



Posts: 11
Joined: 11-June 18




Thank you very much. It's working perfectly now.
Regards.
Go to the top of the page
 
DanielPineault
post Jun 22 2019, 06:08 AM
Post#4


UtterAccess VIP
Posts: 6,765
Joined: 30-June 11



My pleasure.

--------------------
Daniel Pineault (2010-2019 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...(you are responsible for your choices and actions)
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    19th August 2019 - 09:21 AM