Microsoft Access 2007, Macro issue, form and database with phone numbers

我是研究僧i 提交于 2020-01-16 05:28:07

问题


I'm trying to write a little form which accepts some user input, and on the basis of some logic displays one of two possible other forms. Everything is working fine if I use simple, unformatted data, but I hit a problem if the data in question has an input mask of a phone number. Presumably there's a trick here to ignore formatting characters or some such?

The actual logic looks for records in a particular table whose values match the data entered. Something like this cut down example:

A form, which is not associated with any specific table, containing one data entry field, called FormFieldY, and a button whose onClick invokes a Macro whose condition looks for matching data in a table.

     DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0

Now, if I MyColumn in the table has simple text or numeric values this works just fine. However if I apply a Telephone number input mask to that column, I never get a match. I have tried applying an input mask to my form field, or typing literally into the form field a fully formatted number

    (1234) 56789012

neither gives a match. However if instead I hack the macro and enter a suitable hard-coded formatted valueL

         DCount("*","TableX","[MyColumn] = '(1234) 56789012'" ) > 0

It works just fine.


回答1:


I think you may have two issues going on. The first is that your format property displays the parentheses when a user types in a phone number, but those parentheses are not included in the value of FormFieldY --- they are display-only.

You can verify the value of FormFieldY by assigning this code to its After Update event:

Private Sub FormFieldY_AfterUpdate()
    MsgBox Me.FormFieldY 
End Sub

If you want the parentheses stored as part of FormFieldY's value, perhaps you would get more joy by using an input mask rather than a format. With Access 2003, I used this as my text box control's input mask:

!\(999") "000\-0000;0;_

But it's probably easiest to use the Input Mask Wizard (click the button with 3 dots, which is just to the right of the Input Mask line on your control's property sheet). Choose phone number on the first wizard page. On the Wizard page which asks "How do you want to store the data?", select the "With the symbols in the mask" radio button.

Comment from djna: That was the solution, the expression change below seems not to be needed

The other issue is your DCount expression:

DCount("*","TableX","[MyColumn] = [FormFieldY] " ) > 0

I think you should use the value of FormFieldY rather than the name of the control. That may not be clear, so here's what I mean:

DCount("*","TableX","[MyColumn] = '" & Me.FormFieldY & "'" ) > 0


来源:https://stackoverflow.com/questions/5519063/microsoft-access-2007-macro-issue-form-and-database-with-phone-numbers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!