Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2006

Tip: Looking for answers? Try searching our database.

dropped zero's

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Susan - 19 Oct 2006 14:56 GMT
in searching for my problem, i ran across an older post regarding
"Leading zero's in form fields".
http://groups.google.com/group/microsoft.public.word.vba.userforms/browse_thread
/thread/8af7686d3408d26/aaeadbf494226b9a?lnk=gst&q=dropped+zeros&rnum=1#aaeadbf4
94226b9a


the response to this was to make the formfield a TEXT formfield, not a
number formfield, and then all the digits would be kept.  i tried that
but then it doesn't format my information correctly.
in a formfield i am trying to enter a tax id number, which has the
following format:
##.### - ## - ##.###
(there are no spaces but the dashes were hard to see).
the userform textbox entry allows:  050003030100
but when it transfers it to the formfield, formated as a number with
this format, it drops the leading zero and sometimes the ending zero's.
instead of 05.000-30-30.100 i get 5.000-30-30.1
usually this is basically correct but not in the correct format.
but if it were 03 in the center instead of 30, i get 5.000.33.01
which is completely incorrect.
but formatting it as text won't allow the ### format (yes, i know i
COULD enter it with the dots & dashes, but it's faster to leave them
out.).
(i don't have this problem in excel, because it doesn't drop the
zero's.)
any ideas?
susan
Greg Maxey - 19 Oct 2006 18:29 GMT
Susan,

AFAIK, You will need to build a custom string:

Private Sub CommandButton1_Click()
Dim myString As String
myString = Me.TextBox1.Text
If Not IsNumeric(myString) Or Len(myString) <> 12 Then
 MsgBox "You need code in your textbox change event to prevent this."
 Unload Me
 Exit Sub
End If
myString = Left(myString, 2) & "." & Mid(myString, 3, 3) & "-" _
 & Mid(myString, 6, 2) & "-" & Mid(myString, 8, 2) & "." &
Right(myString, 3)
ActiveDocument.FormFields("Text2").Result = myString
Me.Hide
End Sub

> in searching for my problem, i ran across an older post regarding

> "Leading zero's in form fields".
> http://groups.google.com/group/microsoft.public.word.vba.userforms/browse_thread
/thread/8af7686d3408d26/aaeadbf494226b9a?lnk=gst&q=dropped+zeros&rnum=1#aaeadbf4
94226b9a

[quoted text clipped - 20 lines]
> any ideas?
> susan
Susan - 19 Oct 2006 18:50 GMT
thanks Greg - i've never used/built a custom string before......
something new to learn!  <vbg>
i'm going to go TRY it first  <v v bg> and if i
have any questions THEN i'll ask them!
:D
susan
Susan - 19 Oct 2006 19:27 GMT
hiya!  it works!
in this particular document i have a globalmod module
with the sub values(), so i declared MyString there,
and put the value in the sub values() that is called when
needed.
then in the userform code i added the prohibition
regarding non-numerical & <>12.
works like a charm!
thank you very much for showing me how to do this.
susan
Greg Maxey - 19 Oct 2006 19:34 GMT
I only show what I have been shown ;-).

Glad you have it working.

> hiya!  it works!
> in this particular document i have a globalmod module
[quoted text clipped - 6 lines]
> thank you very much for showing me how to do this.
> susan
Tony Jollans - 19 Oct 2006 19:34 GMT
You can make that a little easier with ...

   myString = Format(TextBox1.Text, "@@.@@@-@@-@@.@@@")

--
Enjoy,
Tony

> Susan,
>
[quoted text clipped - 18 lines]
>
> > "Leading zero's in form fields".

http://groups.google.com/group/microsoft.public.word.vba.userforms/browse_th
read/thread/8af7686d3408d26/aaeadbf494226b9a?lnk=gst&q=dropped+zeros&rnum=1#
aaeadbf494226b9a

> > the response to this was to make the formfield a TEXT formfield, not a
> > number formfield, and then all the digits would be kept.  i tried that
[quoted text clipped - 17 lines]
> > any ideas?
> > susan
Greg Maxey - 19 Oct 2006 19:45 GMT
Tony,

Since it is done I don't suppose it can be any easier.  LOL

Showing and being shown is a wonderful thing.

Thanks for showing.  ;-)

> You can make that a little easier with ...
>
[quoted text clipped - 52 lines]
> > > any ideas?
> > > susan
Susan - 19 Oct 2006 19:57 GMT
wow!  now i know how to build a custom string AND format
a textbox!!!
happy happy day
(receiving this "good" advice makes up for all the
"poor" advice i gave in the excel.programming newsgroup
today!)  ha ha
i read where somebody said the best way to learn this stuff
is to try to answer other people's posts, but it isn't working
out too well.  the excel gurus are probably getting tired of
correcting me..............
:/
susan
Greg Maxey - 19 Oct 2006 20:06 GMT
Susan,

I suppose digging around in Help might provide even a blind dog a bone
once in awhile:

>From Help:
@
Character placeholder. Display a character or a space. If the string
has a character in the position where the at symbol (@) appears in the
format string, display it; otherwise, display a space in that position.
Placeholders are filled from right to left unless there is an
exclamation point character (!) in the format string.
&
Character placeholder. Display a character or nothing. If the string
has a character in the position where the ampersand (&) appears,
display it; otherwise, display nothing. Placeholders are filled from
right to left unless there is an exclamation point character (!) in the
format string.

With very limited testing both "@" and "&" appear to workk equally as
well.

> wow!  now i know how to build a custom string AND format
> a textbox!!!
[quoted text clipped - 8 lines]
> :/
> susan
Susan - 19 Oct 2006 21:15 GMT
> Susan,
>
> I suppose digging around in Help might provide even a blind dog a bone
> once in awhile:

yes, i use Help @ home, but for some reason here @ work, Help isn't
installed.........
every time i try to use it the computer searches for the files & can't
find them...... maybe they were accidentally deleted @ some time.
susan
Russ - 20 Oct 2006 08:55 GMT
Susan,
The problem usually is that when Word is installed normally the help files
aren't installed. But they are on the Install Disk and can be installed
later with a 'Custom Install'. See this previous post quote:
------------------------
"VBA is installed by default. However, if you want the HELP files for
VBA, then you must install them separately. And I don't remember which
CD is required for that install. But that doesn't matter. Just install
the Help and the installation will tell you which CD is required."

Dian D. Chapman, Technical Consultant
Microsoft MVP, MOS Certified
Editor/TechTrax Ezine
---------------------------
>> Susan,
>>
[quoted text clipped - 6 lines]
> find them...... maybe they were accidentally deleted @ some time.
> susan

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.