Solved

Format user data from a InputBox

Posted on 2007-11-23
7
1,156 Views
Last Modified: 2010-04-21
I have an input box for a user to enter a social security number.  I would like to format the user input to: XX-XX-XXXX

Is this possible?

Thank you.

sUSocSec = InputBox("Please enter full patient Social Security Number:" & vbCrLf & "Format (XX-XX-XXXX)", "Social Security Number")
0
Comment
Question by:thandel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 20339760
try this

sUSocSec = Format(InputBox("Please enter full patient Social Security Number:" & vbCrLf & "Format (XX-XX-XXXX)", "Social Security Number"), "##-##-####")
0
 
LVL 44

Accepted Solution

by:
Arthur_Wood earned 250 total points
ID: 20339762
rather than asking the user to properly format the entry, you should allow the user to enter 9 digits, then verify that what the entered was in fact 9 numeric digits, and if so, then format the result as you need>

ALso, using an Input Box is not a good idea.  You would be better served to design your own form, and use that instead.  But with the Input Box:


Dim strSSN As String
strSSN = ""
Do Until Len(strSSN) = 9 And IsNumeric(strSSN)
    strSSN = InputBox("Please enter full patient Social Security Number:", "Social Security Number")
Loop
 
strSSN = Left(strSSN, 3) & "-" & Mid(strSSN, 4, 2) & "-" & Right(strSSN, 4)
 
 
AW

Open in new window

0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 250 total points
ID: 20339826
you can remove the format instruction from the input box so the user will just enter the numbers



sUSocSec = Format(InputBox("Please enter full patient Social Security Number:", "Social Security Number"), "##-##-####")
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:thandel
ID: 20339876
Hmmm Arthur interestin... however pressing cancel doesn't take the user out of this... how can the cancel button stop the loop?
0
 

Author Comment

by:thandel
ID: 20339879
Opps I added this... let me do more testing.

If strSSN = "" Then GoTo Exit_Err_SubmitCA_Click
0
 

Author Comment

by:thandel
ID: 20339915
Here is what I"m testing with..... so far its working nicely.

        Do Until Len(strSSN) = 9 And IsNumeric(strSSN)
            strSSN = InputBox("Please enter patient Social Security Number" & vbCrLf & _
            "(without dashes)", "Social Security Number")
            If strSSN = "" Then GoTo Exit_Err_SubmitCA_Click
        Loop
        strSSN = Left(strSSN, 3) & "-" & Mid(strSSN, 4, 2) & "-" & Right(strSSN, 4)
        Me.Notes = "Social Security Number: " & strSSN & vbCrLf & vbCrLf & Me.Notes
0
 

Author Closing Comment

by:thandel
ID: 31410676
Thanks, I split the points up a bit as both solutions answered my question.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question