INF: How to Dial a Phone Number in Microsoft Access
Article ID: Q93696
This article describes a sample user-defined Access Basic function,
DialNumber(), that you can use to dial a telephone number from Microsoft
Access using your computer's modem. This method uses Microsoft Windows
application programming interface (API) function calls.
Although this function will work with Microsoft Access version 2.0, version
2.0 has a new AutoDialer feature that can be used for dialing telephone
numbers. For more information about the AutoDialer feature, search for
"AutoDialer" using the Microsoft Access 2.0 Help menu.
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information on Access Basic, please refer
to the "Introduction to Programming" manual in Microsoft Access version
1.x, or the "Building Applications" manual in version 2.0.
MORE INFORMATION
================
To dial a phone number in Microsoft Access, you can use Microsoft Windows
API calls in the dynamic-link library (DLL) USER.EXE. There are 17
communication API calls available in USER.EXE, but only the following 3 are
used to dial a phone number: OpenComm(), CloseComm(), and WriteComm().
The following steps demonstrate how to create and use the DialNumber()
function.
NOTE: In the following sample code, an underscore (_) is used as a line-
continuation character. Remove the underscore when re-creating this code in
Access Basic.
1. Open the sample database NWIND.MDB.
2. Create a new Access Basic module with the following in the Declarations
section:
Option Explicit
' The number of seconds to wait for the modem to dial before
' .. resetting the modem. If the phone hangs up prematurely
' .. try increasing this value by small increments.
Const WAITSECONDS = 4
Declare Function OpenComm Lib "User" (ByVal lpComName$, _
ByVal wInQueue%, ByVal wOutQueue%) As Integer
Declare Function CloseComm Lib "User" (ByVal nCid%) As Integer
Declare Function WriteComm Lib "User" (ByVal nCid%, _
ByVal lpBuf$, ByVal nSize%) As Integer
Const ID_CANCEL = 2
Const MB_OKCANCEL = 1
Const MB_ICONSTOP = 16, MB_ICONINFORMATION = 64
3. Add the following function to the module:
' ***********************************************************
' FUNCTION: DialNumber()
'
' PURPOSE: To dial a telephone number using the computer's modem
'
' ARGUMENTS:
' PhoneNumber: The telephone number to dial
'
' CommPort: The communications port the modem is connected
' to. Typically, modems are found on COM2, however,
' they can be configured for any COM port.
'
' EXAMPLE:
' Type the following in the Immediate window using a modem
' connected to the COM2 port:
'
' ? DialNumber("555-1212", "COM2")
'
' ***********************************************************
Function DialNumber (PhoneNumber, CommPort As String)
Dim Msg As String, MsgBoxType As Integer, MsgBoxTitle As String
Dim ModemCommand As String
Dim OpenPort As Integer
Dim RetVal As Integer
Dim StartTime
Dim CR As String: CR = Chr$(13)
Dim LF As String: LF = Chr$(10)
' Ask the user to pick up the phone
Msg = "Please pickup the phone and choose OK to dial " _
& PhoneNumber
MsgBoxType = MB_ICONINFORMATION + MB_OKCANCEL
MsgBoxTitle = "Dial Number"
If MsgBox(Msg, MsgBoxType, MsgBoxTitle) = ID_CANCEL Then
Exit Function
End If
' Open the communications port
OpenPort = OpenComm(CommPort, 1024, 128)
If OpenPort < 0 Then
Msg = "Unable to open communication port " & CommPort
GoTo Err_DialNumber
End If
' Send the telephone number to the modem
ModemCommand = "ATDT" & PhoneNumber & CR & LF
If WriteComm(OpenPort, ModemCommand, Len(ModemCommand)) < 0 Then
Msg = "Unable to dial number " & PhoneNumber
GoTo Err_DialNumber
End If
' Wait WAITSECONDS seconds for the phone to dial
StartTime = Timer
While Timer < StartTime + WAITSECONDS
DoEvents
Wend
' Reset the modem and take it off line
ModemCommand = "ATH0" & CR & LF
RetVal = WriteComm(OpenPort, ModemCommand, Len(ModemCommand))
' Close the communications port
RetVal = CloseComm(OpenPort)
Exit Function
Err_DialNumber: 'This is not an On Error routine
Msg = Msg & CR & CR & "Make sure no other devices are using _
communication port " & CommPort
MsgBoxType = MB_ICONSTOP
MsgBoxTitle = "Dial Number Error"
MsgBox Msg, MsgBoxType, MsgBoxTitle
End Function
4. Open the Employees form in Design view.
5. Place a command button with the following properties on the form, next
to the Home Phone field.
Microsoft Access 1.x:
ControlName: btnDialPhone
Caption: Dial
OnPush: =DialNumber([Home Phone], "COM2")
Microsoft Access 2.0:
Name: btnDialPhone
Caption: Dial
OnClick: =DialNumber([Home Phone], "COM2")
6. View the form in Form view. To dial an employee's home phone number,
choose the Dial button.
--
__________________________________________________________________________
Dev Ashish das...@mailnet.ho.att.com
Applied Technologies Organization Holmdel, NJ
AT&T Laboratories
David O'Brien <mor...@ozemail.com.au> wrote in article
<3347FF...@ozemail.com.au>...