开发者

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

开发者 https://www.devze.com 2023-02-21 04:37 出处:网络
I\'m trying to write a little form which accepts some user input, and on thebasis of some logic displays one of two possible other forms. Everything is working fine if I use simple, unformatted data,

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开发者_C百科 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.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消