Microsoft KB Archive/837146

= Dialing rules are ignored when you use the AutoDialer feature in Access =

Article ID: 837146

Article Last Modified on 5/13/2004

-

APPLIES TO


 * Microsoft Office Access 2003
 * Microsoft Access 2002 Standard Edition
 * Microsoft Access 2000 Standard Edition

-





This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

Advanced: Requires expert coding, interoperability, and multiuser skills.



SYMPTOMS
When you use the AutoDialer feature in Microsoft Access, the dialing rules that are set in Access are ignored.

For example, you may set a dialing rule to dial 9 so that you can access an outside phone line for a long-distance phone call. When you use the AutoDialer feature in Access to dial the long-distance phone call, the AutoDialer feature does not prefix the long-distance phone number with 9.



WORKAROUND
To work around this problem, create a form that has the functionality that is similar to the functionality of the AutoDialer feature, and then use the form. To do this, follow these steps:  Start Access. Create a new Access database. In the Database window, click Forms in the Objects section. In the right pane, double-click Create form in Design View.  Create a form. Name the form frmAutoDialXP. The frmAutoDialXP form must have a command button and a text box as follows:

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  Change the Caption property of the Text3 label to Phone number.</li> On the View menu, click Code.</li>  Replace the existing code with the following code in the Visual Basic Editor: 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 = &quot;An error occurred when dialing the phone number.&quot; 'Set the phone number to the value that is shown in the form. stPhoneNumber = Nz(Me.Text_PhoneNumber.Value) lResult = tapiRequestMakeCall(stPhoneNumber, &quot;&quot;, &quot;&quot;, &quot;&quot;) 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 &quot;control.exe modem.cpl&quot;, 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 = &quot;&quot; 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 = &quot;01234567890- ,*#+&quot; 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, &quot;&quot;) boolPhoneWarn = False strPhoneWarn = &quot;This phone number may not dial correctly. &quot; & _ &quot;Double check the phone number. Make sure that the phone number conforms &quot; & _ &quot;to the correct canonical format, and that the phone number does not contain non-valid characters.&quot; & vbCrLf & _ &quot;Example: +1 (425) 555-0187&quot; '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) & &quot;-&quot; & Right(strPhoneInput, 4) Case 8 'Format = '555-0187' Local Call strPhoneCanon = strPhoneInput Case 10 'Format = '7045550187' strPhoneCanon = &quot;+1 (&quot; & Left(strPhoneInput, 3) & &quot;) &quot; & Mid(strPhoneInput, 4, 3) & &quot;-&quot; & Right(strPhoneInput, 4) Case 12 'Format = '(704)5550187' or '704 555-0187' or '704-555-0187' If InStr(1, strPhoneInput, &quot;(&quot;) > 0 Then               strPhoneCanon = &quot;+1 &quot; & Left(strPhoneInput, 5) & &quot; &quot; & Mid(strPhoneInput, 6, 3) & &quot;-&quot; & Right(strPhoneInput, 4)            ElseIf Mid(strPhoneInput, 4, 1) = Chr(32) Then                strPhoneCanon = &quot;+1 (&quot; & Left(strPhoneInput, 3) & &quot;)&quot; & &quot; &quot; & Mid(strPhoneInput, 5)            Else                strPhoneCanon = &quot;+1 (&quot; & Left(strPhoneInput, 3) & &quot;) &quot; & Mid(strPhoneInput, 5)            End If        Case 13            'Format = '(704)555-0187'            strPhoneCanon = &quot;+1 &quot; & Left(strPhoneInput, 5) & &quot; &quot; & Right(strPhoneInput, 8)        Case 14            'Format = '(704) 555-0187'            strPhoneCanon = &quot;+1 &quot; & 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 </li> On the File menu, click Close and Return to Microsoft Office Access.</li> In the Database window, click Save on the File menu.</li> In the Save As dialog box, type frmAutoDialXP in the Form Name box, and then click OK.</li> On the File menu, click Close.</li> In the Database window, click Modules in the Objects section.</li> Click New.</li>  Replace the existing code with the following code in the Visual Basic Editor: 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 &quot;tapi32&quot; _ (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 &quot;frmAutoDialXP&quot;, acNormal,, , , acDialog, strPhoneNumber End Function

'Function to display error messages. Function sDisplayError(strErrNumber As String, strErrDescription As String) MsgBox &quot;An error has occurred.&quot; & vbCrLf & vbCrLf & _ &quot;Error Number: &quot; & strErrNumber & vbCrLf & vbCrLf & _ &quot;Error Description: &quot; & strErrDescription, vbOKOnly + vbExclamation End Function </li> On the File menu, click Save .</li> In the Save As dialog box, type basAutoDialXP in the Module Name box, and then click OK.</li> On the File menu, click Close and Return to Microsoft Office Access.</li> Add an AutoDial button to the frmAutoDialXP form. To do this, follow these steps: <ol style="list-style-type: lower-alpha;"> In the Database window, click Forms under Objects.</li> In the right pane, locate the frmAutoDialXP form. Right-click the frmAutoDialXP form, and then click Design View.</li> <li>Add a command button to the frmAutoDialXP form.</li> <li>In the Command Button Wizard, click Miscellaneous under Categories.</li> <li>Under Actions, click AutoDial, and then click Finish.</li></ol> </li> <li>On the View menu, click Code.</li> <li> Locate the following code: Application.Run &quot;utility.wlib_AutoDial&quot;, stDialStr Replace the previous code with the following code: sOpenDialer (stDialStr) </li> <li>On the File menu, click Save .</li> <li>On the File menu, click Close and Return to Microsoft Office Access.</li> <li>Open the frmAutoDialXP form.</li> <li>In the Phone number box, type +1 (09) 425-5550187, and then click OK.</li></ol>

<div class="moreinformation_section">

Steps to reproduce the problem
<ol> <li>To create a dialing rule, follow these steps: <ol style="list-style-type: lower-alpha;"> <li>If you are using Windows 2000 or the Classic Start menu in Windows XP or in Windows Server 2003, click Start, point to Settings, and then click Control Panel.

If you are using Windows XP or Windows Server 2003 and the menu is not the Classic Start menu, click Start, and then click Control Panel.</li> <li>In Control Panel, click Phone and Modem Options.</li> <li>On the Dialing Rules tab, click New to create a Location profile for the first time.</li> <li>In the Location box, type testLocation .</li> <li>In the Area code box, type 425 .</li> <li>In the To access an outside line for long distance calls, dial box, type 9 .</li> <li>Click OK.</li> <li>On the Phone and Modem Options, click OK.</li></ol> </li> <li>Start Access.</li> <li>Create a new database.</li> <li> Create a new table. Name the table testTable.

The columns details for the table follow:

<pre class="fixed_text">Field name phoneNumber Data type text </li> <li>Open the testTable table in Datasheet view.</li> <li>In the phoneNumber column, type +1 (09) 425-5550187 .</li> <li>On the View menu, point to Toolbars, and then click Customize.</li> <li>On the Commands tab, click Records in the Categories list.</li> <li>In the Commands list, click AutoDialer, and then add AutoDialer to the Datasheet view toolbar.</li> <li>Click Close.</li> <li>In Datasheet view, click the phone number that you want to dial.</li> <li>On the toolbar, click AutoDialer.</li> <li>In the AutoDialer dialog box, click OK.

Notice that the AutoDialer feature does not prefix the phone number with 9.</li></ol>

<div class="references_section">