Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Wanted to replace special characters in MS Access using VB, but more than 1 character


Wanted to replace special characters in MS Access using VB, but more than 1 character

Reply
  #1 (permalink)  
Old 12-03-05, 05:45 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Wanted to replace special characters in MS Access using VB, but more than 1 character

I have never tried to do any VB programming before in Microsoft Access (so keep in mind I am a greenhorn newbie) but I had a problem that needed solving. I have a database full of articles but there is one problem. The articles are full of special characters, that show as boxes, which cannot be removed normally in Access like you can regular characters like a, b, c, 1, 2, 3....etc.

Those special characters are only 2 really. The special characters are the hard return & tab characters. I found this article from Microsoft (http://support.microsoft.com/?kbid=210433 )that will allow you to replace one special character for another character. In that example it replaces the tab character with a % character.

I got that to work for me just fine with a simple replace of the tab for a % BUT...

What I really wanted to do was to replace the tab character with a longer string of text like the html code (&nbsp;&nbsp;&nbsp; ) for three non breaking spaces (in order to keep the tab's look in the html output) (AND was going to also replace the hard returns with <br>). Well problem is this... when the module replaced it
it would place only the & from the first character in the replacement text. Then I went to Mid(strText, intStart, 1) = "&nbsp;&nbsp;&nbsp;" and changed the 1 to 18 and it seemed like it worked but it did not just replace the tabs in the article but also some of the following characters too.

Example: (<tab> represents the tab character)
PHP Code:

List of things to do...

<
tab>take out the trash
<tab>go to store and get soap 
would turn into something like this...
PHP Code:

List of things to do...

&
nbsp;&nbsp;&nbsp;h
&nbsp;&nbsp;&nbsp;et soap 
What I really wanted was this...
PHP Code:

List of things to do...

&
nbsp;&nbsp;&nbsp;take out the trash
&nbsp;&nbsp;&nbsp;go to store and get soap 
I hope this was clear what I was trying to do. I only wanted to replace the tab but I wanted to use more than one character when I do that. I used this code below given by Microsoft....


Code is..
PHP Code:

'============================================================

The following function will:
'   - Find the tabs in a Text or Memo field.
'   
Call another function to replace the tabs.
' ============================================================

Function FindTabs(WhichField As String) As String
   Dim intCounter As Integer
   Dim strText As String
   Dim intStart As Integer

   intStart = 1
   intCounter = 1
   strText = WhichField

   Do Until intCounter = 0
      ' 
Chr(9is the Tab character.
      
' Replace Chr(9) with the ANSI code for the character
      ' 
you are searching for.
      
intCounter InStr(intStartstrTextChr(9))
      
intStart intCounter 1
      
If intCounter And Not IsNull(intCounterThen
         strText 
ReplaceTabs(intCounterstrText)
      
End If
   
Loop

   FindTabs 
strText
End 
Function

'==================================================================
The following function is called from the FindTabs() function. It
' accepts two arguments, intStart and strText. The function replaces tabs
with %. It returns the updated text.
'==================================================================

Function ReplaceTabs(intStart As Integer, strText As String) As String
   ' 
Replace with the character you want to substitute.
   
Mid(strTextintStart1) = "%"
   
ReplaceTabs strText
End 
Function 
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #2 (permalink)  
Old 12-04-05, 08:42 AM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
You might want to try built-in function "Replace".
Code:
strString = Replace(strString, Chr(9), "&nbsp;&nbsp&nbsp;")
Cheers,
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm
Reply With Quote
  #3 (permalink)  
Old 12-04-05, 01:36 PM
cebuy cebuy is offline
Newbie Coder
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Where does this go in the code exactly since I do not see the variable 'strString' in the original code? Please understand I am a novice at this.

strString = Replace(strString, Chr(9), "&nbsp;&nbsp&nbsp;")
__________________
Thanks!
Chris Chandler
WebMaster of:
Loan Quote, Christian eBuy, & North Alabama,
Reply With Quote
  #4 (permalink)  
Old 12-04-05, 05:30 PM
mas_detokyo mas_detokyo is offline
Newbie Coder
 
Join Date: Aug 2005
Location: Tokyo
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
...
Code:
Function FindTabs(WhichField As String) As String 

FindTabs= Replace(WhichField 
, Chr(9), "&nbsp;&nbsp&nbsp;")

End Function
mas
__________________
Visitez: VBA & SAP RFC Function site - http://sapass.metro.client.jp/index.htm
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access - VB Coding MikeFairbrother Visual Basic 2 03-17-06 05:34 AM
VB in MS Access lostgirl12 Visual Basic 0 10-12-05 09:35 PM
Replace any character ronlar PHP 2 09-22-05 12:46 PM
How to replace extended Character with character luv_suresh Perl 1 06-22-05 12:16 AM
Coverting MS Access database to Text file sandeep_mankoo ASP 0 04-17-04 08:48 AM


All times are GMT -5. The time now is 01:14 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.