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 / April 2007

Tip: Looking for answers? Try searching our database.

Text Maniplation in VBA Before Being Put Into a Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shane - 04 Apr 2007 08:11 GMT
Hi.

I'm into an area that has me stumped.  I have a template that reads
database info via DDE.  A field that holds fax numbers is displayed to
the user as (07) 6666 6666.  Due to the nature of the database the
text that is passed to Word is formated 1-07)-6666-6666.  I cannot
change the way the data is passed over due to the relational nature of
the records and table structure so I'd like to reformat it via VBA.

What I don't know how to do is reformat the info before it hits the
document i.e replace and remove characters.  What I would like to do
is take the data when a form loads (no problem as I can do that),
manipulate it into the format required (this I can't do)  then display
it in the form for the user (no problems here either).

Any help would be appreciated.

Regards
Shane
Helmut Weber - 04 Apr 2007 14:20 GMT
Hi Shane,

I think this is not enough information
for providing a good anwer.

1-07)-6666-6666 -->  (07) 6666 6666

It is hardly possible to find out a pattern (!)
from only one Example.

Signature

Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000 (german versions)

Rob - 04 Apr 2007 14:50 GMT
Well, you could always do something naughty like:

FaxString = Replace(FaxString, "1-", "(")

But,  like Helmut said, more info would be good. I'd be interested in
knowing why it's happening and would like to know how you're getting the
value and what data type you're putting it into and how.
Shane - 05 Apr 2007 01:40 GMT
I'm using a CRM product called Goldmine.  In it there is primary
contact page that holds contact info for suppliers, clients, etc.  On
that page is a fax number.  "Attached" to each contact record is a
sub-record for additional contacts. This is another table with a one
to many relationship with the primary contact table.  The info here
may be staff that work for the supplier listed in the primary contact
page.  This table also stores a fax number.

Due to the nature of the table structure and the relationship issues
you launch the document from within Goldmine and tell Goldmine which
record you want to deal with.  Goldmine uses an internal macro (not
the same as a Word macro) to extract the relevant fax info for the
record identified when you launched the template. The template uses
VBA and a DDE request to extract the fax number.  The DDE request is
along the lines of "DDEAUTO Goldmine Data &Fax" where &Fax pulls the
fax field for the appropriate table (primary or secondary).  Sorry if
this isn't clear but usenet isn't a good medium for explaining table
relationships such as Goldmine uses.

I have the fax info entered in Goldmine in the format (07) 1234 5678.
When GM passes the data for a &FAX request it changes it as 1-07)-1234
5678.  (one less - that I originally mentioned (sorry)).  I cannot
change this behaviour.  Changing the format of the fax number to 07
1234 5678 just ends up removing one of the digits in the first group
of four and still stuffs up the formatting.

I can access the fax number field on the main page directly and the
formatting doesn't get changed, it's only when I use the macro to
access the attached secondary contact details.

The Fax number fields are string type.

As far as patterns go...I'm storing data as (xx) yyyy zzzz and is
passed to an external app as 1-xx)-yyyy zzzz.  That's the pattern.
(xx) is the area code.  If the pattern changes then the user hasn't
followed internal procedure and it's not my problem.

Again, there is nothing in Goldmine that can be manipulated to change
this behaviour so I figured the easiest way was to use VBA to
manipulate the text string as it comes across in a standard,
consistent format.  If it doesn't the user hasn't entered the info
correctly.

Cheers

>But,  like Helmut said, more info would be good. I'd be interested in
>knowing why it's happening and would like to know how you're getting the
>value and what data type you're putting it into and how.
Ed - 04 Apr 2007 17:29 GMT
> Hi.
>
[quoted text clipped - 15 lines]
> Regards
> Shane

Hi, Shane.  Try looking through these references to see if any of them
can help.
Ed

http://word.mvps.org/faqs/macrosvba/replacecharinstringcontent.htm
http://word.mvps.org/FAQS/MacrosVBA.htm#Find&Replace

http://msdn2.microsoft.com/en-us/library/aa201315(office.11).aspx
http://msdn2.microsoft.com/en-us/library/aa189291(office.10).aspx
http://www.microsoft.com/technet/prodtechnol/office/office2000/solution/part2/pa
rt2.mspx?mfr=true

Greg Maxey - 04 Apr 2007 17:49 GMT
Here is one way you might consider:

Sub ScratchMacor()
Dim myString As String
myString = "1-07)-6666-6666"
myString = Replace(Replace(myString, "1-", "("), "-", " ")
MsgBox myString
End Sub

> Hi.
>
[quoted text clipped - 15 lines]
> Regards
> Shane
Shane - 05 Apr 2007 01:58 GMT
Thanks Ed and Greg.

Greg, your code did it.  I'll pass this on to other people as it's an
issue that's been around for a while.

Cheers

>Here is one way you might consider:
>
[quoted text clipped - 24 lines]
>> Regards
>> Shane
 
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.