sms send bottam vb code need help

shobhanauto

New member
Local time
Today, 16:25
Joined
Dec 17, 2023
Messages
6
Someone help me. I am trying hard, but the SMS is not going through.

In my database, there is a Customers table.
MobileNumber = MobileNumber
Customer name = CompanyName


I GOT ERROR

' Assuming CustomerID is a control on the form
Dim CustomerID As Long ' Ensure this matches the data type of CustomerID
CustomerID = Me.CustomerID.Value ' Access CustomerID directly from the form

' Use DLookup to retrieve customer mobile number and company name from Customers table based on CustomerID
customerMobile = DLookup("MobileNumber", "Customers", "CustomerID = " & CustomerID) ' For numeric CustomerID
companyName = DLookup("CompanyName", "Customers", "CustomerID = " & CustomerID) ' For numeric CustomerID

' Display the retrieved values
MsgBox "Customer Mobile: " & customerMobile
MsgBox "Company Name: " & companyName

' Check if the mobile number is valid
If IsNull(customerMobile) Or customerMobile = "" Then
MsgBox "Mobile number not found for this customer.", vbExclamation
Exit Sub
End If

' Check if company name is valid
If IsNull(companyName) Or companyName = "" Then
MsgBox "Company name not found for this customer.", vbExclamation
Exit Sub
End If
 
Screenshot_22.png
here is screenshot and i dont understand why i cant post full vba code said error
 
Use code tags.
What is the error???
 
That is telling you the data types are not the same.
 
why i cant post full vba code its give error

Your content can not be submitted. This is likely because your content is spam-like or contains inappropriate elements. Please change your content or try again later. If you still have problems, please contact an administrator.
 
I would remove that ASAP.
You are giving away your API key?
 
For the benefit of others, here is the code.
So show the table in design mode for CustomerID, as Access is saying they are not the same, and I can see the variable is Long.
Code:
Private Sub SendSMS_Click_Click()

    ' Define variables for SMS API parameters
    Dim apiUrl As String
    Dim apiKey As String
    Dim clientId As String
    Dim senderId As String
    Dim messageText As String
    Dim customerMobile As String
    Dim companyName As String
    Dim response As String
    Dim objHttp As Object
    Dim unicode As String

    ' Set SMS API details (replace with your actual API information)
    apiUrl = "https://api.smsq.global/api/v2/SendSMS?"
    apiKey = "InsertKeyHere"
    clientId = "YouClientID"
    senderId = "SHOBHANAUTO"
    unicode = "false"

    ' Assuming CustomerID is a control on the form
    Dim CustomerID As Long ' Ensure this matches the data type of CustomerID
    CustomerID = Me.CustomerID.Value ' Access CustomerID directly from the form

    ' Use DLookup to retrieve customer mobile number and company name from Customers table based on CustomerID
    customerMobile = DLookup("MobileNumber", "Customers", "CustomerID = " & CustomerID) ' For numeric CustomerID
    companyName = DLookup("CompanyName", "Customers", "CustomerID = " & CustomerID) ' For numeric CustomerID

    ' Display the retrieved values
    MsgBox "Customer Mobile: " & customerMobile
    MsgBox "Company Name: " & companyName

    ' Check if the mobile number is valid
    If IsNull(customerMobile) Or customerMobile = "" Then
        MsgBox "Mobile number not found for this customer.", vbExclamation
        Exit Sub
    End If

    ' Check if company name is valid
    If IsNull(companyName) Or companyName = "" Then
        MsgBox "Company name not found for this customer.", vbExclamation
        Exit Sub
    End If

    ' Retrieve order information from the Orders table
    Dim Subtotal As Currency
    Dim PREVDUE As Currency
    Dim ToDAYpay As Currency
    Dim lessPayment As Currency
    Dim totalAmountDue As Currency
   
    ' Set values from the Orders table (ensure these fields exist in your form)
    Subtotal = Nz(Me.TODAYBILL.Value, 0)          ' Subtotal
    PREVDUE = Nz(Me.BFAmount.Value, 0)            ' Previous Due (BfAmount)
    ToDAYpay = Nz(Me.ToDAYpay.Value, 0)           ' Today's payment (ToDAYpay)
    lessPayment = Nz(Me.LESSAM.Value, 0)          ' Less payment (LESSAM)
   
    ' Calculate total due
    totalAmountDue = (Subtotal + PREVDUE) - (lessPayment + ToDAYpay + Nz(Me.PKDAYPAY.Value, 0))

    ' Create the SMS message text
    messageText = "Dear " & companyName & ", Your total bill is BDT " & Format(Subtotal, "Currency") & _
                  ". Previous due: " & Format(PREVDUE, "Currency") & _
                  ". Payment received today: " & Format(ToDAYpay, "Currency") & _
                  ". Total due: " & Format(totalAmountDue, "Currency") & "."

    ' Create the full API request URL
    Dim fullUrl As String
    fullUrl = apiUrl & "ApiKey=" & apiKey & "&ClientId=" & clientId & "&SenderId=" & senderId & _
              "&Message=" & messageText & "&MobileNumbers=88" & customerMobile & "&Is_Unicode=" & unicode

    ' Initialize HTTP object for sending the request
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
   
    ' Send the request
    objHttp.Open "GET", fullUrl, False
    objHttp.Send

    ' Get response from the API
    response = objHttp.ResponseText

    ' Check the response for success
    If InStr(response, "SUCCESS") > 0 Then
        MsgBox "SMS sent successfully to " & companyName & "!"
    Else
        MsgBox "Failed to send SMS. Response: " & response
    End If

    ' Clean up the object
    Set objHttp = Nothing

End Sub
 
MY PROBLAM SLOVE I MOVE TO TABLE TO COMBOX BOX

' Retrieve mobile number from Customer
customerName = Me.Customer

' Retrieve mobile number from Combo241
customerMobile = "88" & Me.Combo241 ' Adding 88 to the mobile number

Thank you

Gasman for you time and help​

 
Give your controls meaningful names.
6 months down the line Combo241 is not going to mean anything to anyone :(
 
BTW, the reason you were unable to post that code was due to the url in the code.
New users have to wait quite a lengthy time before they can post links?

I would like to ask you a favour.
Can you please copy the code I posted, BUT, you need to put it again within code tags and post back how you got on?
Use the </> button to do so.
 

Users who are viewing this thread

Back
Top Bottom