Microsoft Access Office VB VBA Help and Examples
           
             

Dialing a modem from code

This example shows how to dial a number through a modem or how to send data via a comm port. Open a new form and on the toolbar click the more controls button (it's the one with the hammer on) and scroll down and choose the Microsoft Communications Control (Version X). The verison number is dependant on apps installed like Visual Basic and service packs e.t.c. Please note the control used to ship with Internet Explorer as a design time control it now only ships with developer programs.

    Click and drag with the tool selected and you will see a button type object appear with a phone on it. Double click it and set the comm port that is valid for you. Most modems sit on com ports 2,3,4. Click the OK button. Rename the object by viewing it's properties to something meaningful to your application. For this example I'm going to name it ModemCom2.

    Then in code use the following:-

ModemCom2.PortOpen = True
ModemCom2.Output = "ATDT 01234567890" & vbCr
MsgBox "Have dialed, pickup receiver. Click ok when finished"
ModemCom2.PortOpen = False 'Hangs up

This piece of code dials the phone number 01234567890. Please note after closing the port using ModemCom2.PortOpen = false, the call will be disconnected. If you want to handshake you will need to check the buffer.

Dim ModemStr as String
Do
    Doevents
    If ModemCom2.InBufferCount Then
          ModemStr = ModemStr + ModemCom2.Input
          If InStr(ModemStr, "OK") Then
             Exit Do
           End If
    End If
Loop

When it exits the do loop the phone number has been dialed. The computer the other end needs to be a listener and will listen for a command you send. If you have ever heard a fax machine you will know that it sends a specific beep every few seconds while waiting for the receiving computer to pick up.

 
HOME   SEARCH SITE   PRIVACY POLICY   CONTACT
The code and application content of this site is copyright of Smiley I.T. and as such reproduction in any form which is for commercial use requires the permission of the Webmaster. Any use of this code for non-commercial use only requires a link or comment back to the original page you took the code from.