SMSLibX

SMS for the office / SMS for software developers

 

 

SMS software for GSM modem/phones SMS Tutorials >

Sending SMS from Access database

This tutorial shows how to send/receive SMS from Access
database tables, using SMSLibX (ActiveX DLL) and a GSM
modem or phone.

Index

  1. How to start
  2. Using the example SMS database
    • Database structure
    • How to send and receive SMS
    • Extending the database
  3. Building your own SMS database
    • Integrating SMSLibX.dll into Access
    • How to send and receive SMS from VBA
  4. Best practices for VBA programmers
    • MsgBox eats your messages!
    • Using DoEvents in your loops
    • Events and time-consuming operations
  5. Troubleshooting

 

1. How to start

  1. Download and install SMSLibX on your PC.
  2. Download and install the example SMS database.
  3. Install and connect your GSM modem (or phone) to your PC.
    If you don't have a compatible GSM device, then you can use the simulation mode.

Please note:

  • Anyone can use this example.
    You're not required to be expert in Access or VBA programming, unless you want to modify the example database, or build your own SMS database.
  • The reference environment is MS Access 2000.
    The example is also compatible with later Access versions.

 

2. Using the example SMS database

SMS from Access database tables

 

2.1  Database structure

The most important database tables are TPhonebook and TMessages (containing all SMS messages classified through the MessageStatus field).

The following queries can be used to filter TMessages, as like as they were real tables:

Database Query

Filters TMessages on... Contains...
QMessagesSent MessageStatus="Sent" Sent messages
QMessagesReceived MessageStatus="Received" Received messages
QUnread Unread=true Unread messages
QMessagesOutbox MessageStatus="TO SEND" (or null) Messages to be sent

 

2.2  How to send and receive SMS

To configure your system:

  • Select the appropriate Modem type and Port, then click on the Connect button.

To send SMS from the form:

  • Insert phone number and message text, then click on Send SMS button.
  • If you want to send multiple SMS, please select more recipients from the Phonebook list, or input phone numbers separated by ; (semicolon) in the related field.

To send SMS from a table:

  • Insert your messages into QMessagesOutbox query (or TMessages table).
    For each message, set the MessageStatus field = "TO SEND" or null.
  • Click on the Send from Outbox button.

To receive SMS in a table:

  • Received SMS are automatically stored into TMessages table and immediately displayed on the related message list. If this doesn't happen, please activate the SMS polling option from the Receive SMS section.

 

Most recent Nokia and Symbian phones do not allow reading received SMS from PC through AT commands (i.e. the technology we are using). With these devices you will be able to send, but not to receive SMS from PC, unless you use the original software provided by the constructor.

 

You can examine the VBA source code used to send/receive SMS, by clicking on menu Tools > Macro > Visual Basic editor. In the next chapter you will learn how to send/receive SMS from VBA.

 

2.3  Extending the database

This example database and the related VBA source code can be extended as you like and freely re-used in your own applications.

For instance, you can:

  • Extend the VBA source code inserting functions like:
    periodic SMS sending, auto-reply SMS, data import/export, update other databases etc.
  • Insert SMS to be sent into TMessages table from external applications
    (e.g. from Visual Basic, C# or C++ by ADO, or from ASP or JSP web sites, or from other Access or SQL Server databases, creating a link to TMessages table)
  • Read received SMS from TMessages table from external applications
    (same as above)

SMS&Co rejects any responsibility for possible consequences associated with the use of this example and/or its SMS software.

 

3. Building your own SMS database

This section is dedicated to Access/VBA programmers.
You will learn how to:

  1. Integrate SMSLibX into the Access develop environment and VBA code;
  2. Use SMSLibX objects and methods in your VBA code, to send and receive SMS.

 

3.1  Integrating SMSLibX.dll into Access

  1. Open an existing Access database (or create a new one).
  2. Open or create a VBA form or class module,
    then switch to VBA source code (Tools > Macro > Visual Basic editor).
    Common code modules (.bas in VB6) are not suitable for SMSLibX integration, as they do not allow to catch events raised by SMSLibX (and any other COM object).
  3. Set up a reference for SMSLibX.dll (Tools > References menu).
    If you can't find SMSLibX into the list, please use the Browse button to locate it.
    SMSLibX must have been previously installed on your system.

Now you're ready to use SMSLibX objects and methods directly in your source code.

  • To browse SMSLibX objects and methods, open the Object Viewer (F2) and select SMSLibX library.
  • Contextual help is available when you select SMSLibX items and press F1.
  • Code completion is available on SMSLibX items, e.g. using Ctrl+SPACE, Ctrl+J etc.

 

To learn SMSLibX programming basics in 5 minutes, we recommend the
Quick Start Guide from SMSLibX Help.

 

3.2  How to send and receive SMS from VBA

You can use the following VBA source code in an Access form or class module, in order to send and receive SMS messages.

' Declare SMSModem object
Public WithEvents Modem As SMSModem


' Send SMS
Private Sub cmdSendMessage_Click()
	
  ' Open modem communication
  Set Modem = New SMSModem
  Modem.LogTrace = True
  Modem.OpenComm gsmModemSimulator, 3, , smsNotifyAll
	
  ' Send message
  Call Modem.SendTextMessage("+393401234567", "Hello world")


End Sub


' Receive SMS by event
Private Sub Modem_MessageReceived(Message As SMSLibX.SMSDeliver)
  MsgBox "New message received from " & Message.Originator & ":" _
    & vbCrLf & vbCrLf & Message.Body, _
    vbInformation, "New message received"
End Sub
          

 

Comments:

  • SMSModem is the most important object in the SMSLibX library.
  • The WithEvents clause is essential in order to catch events raised by SMSModem.
  • In the OpenComm method call, you must replace the gsmModemSimulator
    parameter value with your modem type (e.g. gsmModemSiemens, gsmModemNokia...) Here's a good opportunity to try the code auto-completion.
  • You must replace the value 3 (= COM3) with the actual modem COM port number.
  • Please see SMSLibX Help for full documentation of SMSLibX objects and methods.

 

4. Best practices for VBA programmers

Please read these notes carefully – they are very important for a good SMSLibX programming practice!

 

4.1  MsgBox eats your messages!

You may not know that... while there's an opened MsgBox or InputBox dialog in your application, VBA suppresses events generated by timers, forms, controls and any ActiveX components. Events are not simply delayed, but definitively suppressed (see Microsoft Knowledge Base 76557 article).

As possible consequence for this behaviour, you may loose events notifying received SMS (and similar) if they are raised while a MsgBox is open – and that eventuality can't be controlled, since it depends on user.

As a work-around, you should redefine the VBA MsgBox function, replacing it with the MessageBox API from Windows, which does not suppress events (see Microsoft Knowledge Base 76557 article).
A concrete MsgBox re-definition example is available in the example database provided with this tutorial.

 

4.2  Using DoEvents in your loops

If your VBA application cycles over a list of SMS messages to be sent – or performs any other time-consuming operations – then you should provide a DoEvents statement in your loop (or time-consuming operaton).

This will allow SMSLibX to raise its events in real-time, notifying received messages, delivery reports, modem status updates etc. without significant delays.

 

4.3  Events and time-consuming operations

Never put time-consuming operations in the VBA code managing SMSLibX events (e.g. MessageReceived etc.), since SMSLibX relies on the calling thread for further message management and notification.

As a general rule, the event management should never take more than 1 second.

If you want to send an automatic reply SMS to each incoming SMS, a good practice is: (a) create and store the reply message in a table (b) write a separate method activated by a timer (e.g. every 15-30 seconds) to process the message sending queue.
In this way, you will not charge the SMS reception event with the 3-4 seconds needed for SMS sending.

 

5. Troubleshooting

 

5.1  SMSLibX registration problems

If SMSLibX is not correctly registered on your system, one of the following errors should appear when you open the example database:

  1. Error: Cannot find SMSLibX.dll
  2. The expression [...] produced the following error: Can't find project or library
  3. Error #429: ActiveX component cannot create object

To resolve the issue, please verify that SMSLibX has been previously installed on your system – then, if needed, restore the reference to SMSLibX.dll as explained in the first part of this tutorial.

 

5.2  Other problems with SMSLibX

For other kind of problems, please refer to the Troubleshooting section of SMSLibX Help.

NEWS

SMS USAGE CONTEXTS

  • SMS for your business

    - Working teams
    Contact your customers and mobile co-workers by SMS.
    - Mobile marketing
    Contact your audience with friendly SMS communication.

  • SMS for public services

    - Services and associations
    Contact service subscribers and associates by SMS.
    - Commercial consultants
    Remind fiscal deadlines to your customers with an SMS.
    - Medical offices
    Send appointment reminders to your patients by SMS.
    - Schools
    Keep in contact with parents and students by SMS.

  • Do more with SMS...

SUMMER CLOSURE

We'll be closed for holidays
from June 12 to 22, 2017.


Modem orders collected during this period will be delivered in the following workdays.

SMS software licenses will be released within 48 hours, even during this period.

FOCUS ON...