This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
Advanced: Requires expert coding, interoperability, and multiuser skills.
Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.
View products that this article applies to.
Form ----------------------------------- Form Name: frmAutoDialXP Form Caption: AutoDialer XP Command Button ------------------------------------ Name: Button_OK Caption: &OK Command Button ------------------------------------ Name: Button_Cancel Caption: &Cancel Command Button ------------------------------------ Name: Button_Setup Caption: &Setup... Text Box ------------------------------------ Name: Text_PhoneNumber Text Box ------------------------------------ Name: Text_Warn
Option Compare Database
Option Explicit
'The code for this form requires the module 'basAutoDialXP' to work.
Private Sub Button_OK_Click()
On Error GoTo Button_OK_Click_Err
' Variable to hold the phone number.
Dim stPhoneNumber As String
' Variable to hold the return code from the API call.
Dim lResult As Long
' Variables to hold error messages.
Dim stNTNotSupported As String
Dim stErrorDialing As String
Dim stInvalidChars As String
stErrorDialing = "An error occurred when dialing the phone number."
'Set the phone number to the value that is shown in the form.
stPhoneNumber = Nz(Me.Text_PhoneNumber.Value)
lResult = tapiRequestMakeCall(stPhoneNumber, "", "", "")
If lResult <> 0 Then
MsgBox stErrorDialing, vbOKOnly + vbInformation
GoTo Button_OK_Click_Exit
End If
Button_OK_Click_Exit:
'Uncomment to automatically close frmAutoDialXP.
DoCmd.Close acForm, Me.Name
Exit Sub
Button_OK_Click_Err:
sDisplayError Err.Number, Err.Description
Resume Button_OK_Click_Exit
End Sub
Private Sub Button_Cancel_Click()
On Error Resume Next
DoCmd.Close acForm, Me.Name
End Sub
Private Sub Button_Setup_Click()
On Error GoTo Button_Setup_Click_Err
Shell "control.exe modem.cpl", WindowStyle:=1
Button_Setup_Click_Exit:
Exit Sub
Button_Setup_Click_Err:
sDisplayError Err.Number, Err.Description
Resume Button_Setup_Click_Exit
End Sub
Private Function FValidPhoneNumber(ByRef stPhoneNumber As String) As Boolean
Dim ich As Integer
Dim ichLen As Integer
Dim stCh As String
Dim stPhoneClean As String
Dim stValidChars As String
Dim boolInvalidCharsFound As Boolean
'Get the length of the phone number that is based on the number of characters.
ichLen = Len(stPhoneNumber)
'Initialize variables.
stPhoneClean = ""
boolInvalidCharsFound = True
'This routine loops through each character in the phone number and then strips non-valid characters.
'Non-valid characters are letters and characters that are not in the strValidChars variable.
stValidChars = "01234567890- ,*#+()"
For ich = 1 To ichLen
stCh = Mid$(stPhoneNumber, ich, 1)
If InStr(stValidChars, stCh) > 0 Then
stPhoneClean = stPhoneClean & stCh
Else
boolInvalidCharsFound = False
End If
Next ich
'Set the phone number to the revised phone number.
stPhoneNumber = stPhoneClean
FValidPhoneNumber = boolInvalidCharsFound
'FValidPhoneNumber = (Len(stPhoneClean) > 0)
End Function
Private Sub Form_Load()
'This code makes an educated guess as to the type of phone number that is being
'passed and then tries to apply the correct canonical format.
'You must examine this code and then make any changes that you may have to.
Dim strPhoneInput As String
Dim strPhoneCanon As String
Dim boolPhoneWarn As Boolean
Dim strPhoneWarn As String
Dim intPhoneInputLen As Integer
'Set initial values.
strPhoneInput = Nz(Me.OpenArgs, "")
boolPhoneWarn = False
strPhoneWarn = "This phone number may not dial correctly. " & _
"Double check the phone number. Make sure that the phone number conforms " & _
"to the correct canonical format, and that the phone number does not contain non-valid characters." & vbCrLf & _
"Example: +1 (425) 555-0187"
'Check for non-valid characters.
If Not FValidPhoneNumber(strPhoneInput) Then
boolPhoneWarn = True
End If
intPhoneInputLen = Len(strPhoneInput)
Select Case intPhoneInputLen
Case 0
'No phone number is passed.
strPhoneCanon = strPhoneInput
boolPhoneWarn = True
Case 7
'Format = '5550187' Local Call
strPhoneCanon = Left(strPhoneInput, 3) & "-" & Right(strPhoneInput, 4)
Case 8
'Format = '555-0187' Local Call
strPhoneCanon = strPhoneInput
Case 10
'Format = '7045550187'
strPhoneCanon = "+1 (" & Left(strPhoneInput, 3) & ") " & Mid(strPhoneInput, 4, 3) & "-" & Right(strPhoneInput, 4)
Case 12
'Format = '(704)5550187' or '704 555-0187' or '704-555-0187'
If InStr(1, strPhoneInput, "(") > 0 Then
strPhoneCanon = "+1 " & Left(strPhoneInput, 5) & " " & Mid(strPhoneInput, 6, 3) & "-" & Right(strPhoneInput, 4)
ElseIf Mid(strPhoneInput, 4, 1) = Chr(32) Then
strPhoneCanon = "+1 (" & Left(strPhoneInput, 3) & ")" & " " & Mid(strPhoneInput, 5)
Else
strPhoneCanon = "+1 (" & Left(strPhoneInput, 3) & ") " & Mid(strPhoneInput, 5)
End If
Case 13
'Format = '(704)555-0187'
strPhoneCanon = "+1 " & Left(strPhoneInput, 5) & " " & Right(strPhoneInput, 8)
Case 14
'Format = '(704) 555-0187'
strPhoneCanon = "+1 " & strPhoneInput
Case 17
'Format = '+1 (704) 555-0187'
strPhoneCanon = strPhoneInput
Case Else
strPhoneCanon = strPhoneInput
boolPhoneWarn = True
End Select
If boolPhoneWarn = True Then
Me.Text_Warn.Value = strPhoneWarn
End If
Me.Text_PhoneNumber.Value = strPhoneCanon
Form_Load_Exit:
Exit Sub
Form_Load_Err:
sDisplayError Err.Number, Err.Description
Resume Form_Load_Exit
End Sub
Option Compare Database
Option Explicit
'This module is required for the revised AutoDial form (frmAutoDialXP)
'that replaces the one that is included with Access.
'This AutoDial feature is compatible with Microsoft Windows 2000 dialing rules and with Windows XP dialing rules.
'API Function Declaration.
Declare Function tapiRequestMakeCall Lib "tapi32" _
(ByVal lpszDestAddress As String, _
ByVal lpszAppName As String, _
ByVal lpszCalledParty As String, _
ByVal lpszComment As String) As Long
'Function to open frmAutoDialXP.
Function sOpenDialer(strPhoneNumber As String)
DoCmd.OpenForm "frmAutoDialXP", acNormal, , , , acDialog, strPhoneNumber
End Function
'Function to display error messages.
Function sDisplayError(strErrNumber As String, strErrDescription As String)
MsgBox "An error has occurred." & vbCrLf & vbCrLf & _
"Error Number: " & strErrNumber & vbCrLf & vbCrLf & _
"Error Description: " & strErrDescription, vbOKOnly + vbExclamation
End Function
Application.Run "utility.wlib_AutoDial", stDialStr
sOpenDialer (stDialStr)
Field name phoneNumber Data type text
Keywords: KB837146, kbprb