473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

How to use Input Mast in SQL Statement

I'm pulling a phone number field in a form via SQL but it doesn't display as the Input Mask dictates in just this one form. All reports and other forms show it correctly so I'm wondering if there is a way to use the mask via format in the SQL statement?

The mask is: \(999") "000\-0000\ 9999;0;_ (as it is in the Customers table)

The mask formats a phone number field that shows, if there, an extension.

Example:
9545651055 13 will display as (954) 565-1055 13

Here is the code I have that does everything with the exception of formatting the [Business Phone] field.

Expand|Select|Wrap|Line Numbers
  1. SELECT [Customers Extended].ID, [Customers Extended].[Customer Name], [Customers Extended].[Company], FORMAT ('\(999") "000\-0000\ 9999;0;_')([Customers Extended].[Business Phone]) As [Business Phone], [Customers Extended].[Mobile Phone], [Customers Extended].[Fax Number] 
  2. FROM [Customers Extended] 
  3. WHERE (([Customers Extended].ID)<>Form!ID) And (([Customers Extended].[Customer Name]) Like "*" & [txtCustNameContains] & "*") And (([Customers Extended].[Company]) Like "*" & [txtCompanyNameContains] & "*") 
  4. ORDER BY [Customers Extended].[Customer Name];
  5.  
Oddly enough the fax and mobile number fields, both use mask (@@@) @@@-@@@@, both display correctly in the code above. Of course the problem with the business phone is some have extensions.

How can I get these results displayed with the business phone formatted correctly?

Thanks,
Sep 20 '16 #1

✓ answered by jforbes

There is a difference between an Input Mask, Format, VBA Format, and SQL Format.

There are a lot of similarities between an Input Mask and Formatting when it comes to a TextBox. For a TextBox, the Input Mask will define how the TextBox acts when the User is entering the Data. It can also make sure that the Mask is stored along with the Data. And it can re-apply the mask when the data is displayed. So if you want to save the parenthesis for the phone number in your field, then using an Input Mask will make this a lot easier.

Performing any sort of formatting in SQL is usually a bad idea. There are plenty of exceptions to this, but it's usually best to return Raw Data, then perform the formatting in a Report or Form.

Usually in this situation, an Input Mask is either setup on the field in the Table or placed on the TextBox of the Form. ...or both, I think if an Input Mask is put on a Field in the Table, when the field is Dropped on a Form or a Report, the Input Mask for the Field is inherited from the Table.

So, to get your stuff working, remove any Formatting in the SQL Select. Remove the Formatting from the Business Phone TextBox. Then I think if you set the Business Phone TextBox's Input Mask to \(999\)999\-9999\ 9999 it should start working for you.

Either way, I don't think you should be messing with Formatting at all for this as it is limited in comparison to an Input Mask. For the Fax and Mobile number working with the Format is an option that you can continue to work with, but the Input Mask wont be available for Data Entry.

Also, there is a button with Tripple Dots (...) on the Input Mask Property that will open a wizard that might help you.

4 1888
jforbes
1,107 Expert 1GB
Is this not displaying correctly on a Form, Report or Query?

Also, this syntax is unfamiliar to me:
Expand|Select|Wrap|Line Numbers
  1. FORMAT ('\(999") "000\-0000\ 9999;0;_')([Customers Extended].[Business Phone])
Could you explain a little more of what you are attempting to do?
Sep 20 '16 #2
The problem with this one is there is no actual field to place a mask on as this is being written "on-the-fly" through a SQL statement.

I've created a search from to find customer details which is tied to a SQL Query as the record source. I'm using this query as the source as it combines the first name/last name fields into "Customer Name". What I need/want to do is use the same type of masking for the format of this column in the displayed results. The mask (as it is used in the database is written like this:
Expand|Select|Wrap|Line Numbers
  1. \(999") "000\-0000\ 9999;0;_
What it does is format the string of numbers into groups of (xxx) xxx-xxxx AND the last 9999 part leaves room for a 4 digit extension which is displayed as (xxx) xxx-xxxx ____ (without the underscores). See attached photo.

Oddly, some of the records are showing formatted but other are not. They are stored the same in the database all as numbers only - no spaces or other characters at all. I'm stumped.

Terry
Attached Images
File Type: jpg customer_search.jpg (51.7 KB, 207 views)
Sep 21 '16 #3
OK. Figured it out, not the input mask part but the data entry part. If they type the numbers it works if the copy/paste them in the Customers database then the number doesn't display correctly. Not sure why.

Anyway around that? Anyway to make the SQL Select statement format the business number field IN the statement? This way it winds up displaying correctly everywhere?

OR

Is there a way to pull all the business numbers as numbers ONLY, stripping out anything else, then upload them back again? Would that even work?

Thanks,
Sep 21 '16 #4
jforbes
1,107 Expert 1GB
There is a difference between an Input Mask, Format, VBA Format, and SQL Format.

There are a lot of similarities between an Input Mask and Formatting when it comes to a TextBox. For a TextBox, the Input Mask will define how the TextBox acts when the User is entering the Data. It can also make sure that the Mask is stored along with the Data. And it can re-apply the mask when the data is displayed. So if you want to save the parenthesis for the phone number in your field, then using an Input Mask will make this a lot easier.

Performing any sort of formatting in SQL is usually a bad idea. There are plenty of exceptions to this, but it's usually best to return Raw Data, then perform the formatting in a Report or Form.

Usually in this situation, an Input Mask is either setup on the field in the Table or placed on the TextBox of the Form. ...or both, I think if an Input Mask is put on a Field in the Table, when the field is Dropped on a Form or a Report, the Input Mask for the Field is inherited from the Table.

So, to get your stuff working, remove any Formatting in the SQL Select. Remove the Formatting from the Business Phone TextBox. Then I think if you set the Business Phone TextBox's Input Mask to \(999\)999\-9999\ 9999 it should start working for you.

Either way, I don't think you should be messing with Formatting at all for this as it is limited in comparison to an Input Mask. For the Fax and Mobile number working with the Format is an option that you can continue to work with, but the Input Mask wont be available for Data Entry.

Also, there is a button with Tripple Dots (...) on the Input Mask Property that will open a wizard that might help you.
Sep 21 '16 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: dmiller23462 | last post by:
Hey guys.... I put an error-handling in my page and have it posted at the complete end of the code, see below(when people were putting in 's I was getting the delimiter errors). Great, I...
5
by: Steve | last post by:
Hello, I've been a PHP programmer for a number of years and have just started to learn JS. My Employer (a water analysis lab) wants what should be a very simple .js written that basically takes...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
1
by: javedna | last post by:
Can PHP help with the following as I have tried in the MYSQL Forums and cant get any help Thanks Nabz ---------------------------------------- Hi I am developing a PHP MYSQL questionnaire...
2
by: Killer42 | last post by:
The Input #1 statement simply reads in one line from a text file (in this case you INI file) and places the values from it into one or more variables. So what you are reading in this statement is...
10
by: scooby dooby | last post by:
I have an input box statement which can take a integer as below: InputBox("eneter the number") ----- ------- If the user doesn't enter any input for a particular time say 30 secs, i should be...
40
by: chhines | last post by:
I have a very long IIf statement. I think maybe I've reached the limit of how many choices you can have in the control source "Build" statement of a text box on a form. Really, the IIF statement is...
5
by: omar999 | last post by:
I have a CMS which displays some flight routes, alongside prices, dates which is using asp and sql server 05. works well - i.e an update on the CMS page populates the sql table and then the asp...
2
by: mark farid | last post by:
I am trying to write a really basic program based on a trivia game. i have two problems. the first, is that i do not know how to assign a variable whose value will increase with time. my second...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.