Discussion Locked

Access converting tab to | (pipe)

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Got a problem with Accessediting in textbox. When I paste a text containing a text with a tab in Access converts it to a |.

Like this: I love techrepublic!!!
I|love|techrepublic!!!

What to do? Need an urgent answer!

Crowmoor

8 replies

by vomastic

Access cannot recognize tab characters because, to Access, using a tab key tells it to go to the next field. Take out the tab and replace it with spaces.

by tmaclennan

What do you want to happen? Tabs won't work inside an access text field, they are a control character. If you want them to be spaces, either clean up your source file to remove tabs before you cut and paste, or build a macro to hunt and replace pipes with something else.

by peyison

There are several methods for fixing this, depending on how your interface works. One way is to put code in the textbox's change event to remove tabs. Something like:

Private Sub tbxText1_Change()
tbxText1 = RemoveTabs(tbxText1)
End Sub

Function RemoveTabs(asText As String) As String
Dim I As Integer
Dim sChar As String
Dim sResult As String

For I = 1 To Len(asText)
sChar = Mid$(asText, I, 1)
If sChar = Chr(9) Then
sResult = sResult & " "
Else
sResult = sResult & sChar
End If
Next

RemoveTabs = sResult
End Function

Anytime the text in tbxText1 changes, the RemoveTabs function is called. When you paste data in the text box, the Change event would fire. A problem with this method is that every time you edit the text in the textbox, the RemoveTabs function would be called - after every character entered or deleted. If you don't have to edit the text after pasting it, this might be a good solution.

If you will have a lot of edits after the text is pasted, it would probably be better to have a command button that calls RemoveTabs for the textbox(s) after you paste:

Private Sub cmdRemoveTabs_Click()
'--use this button after pasting all text
tbxText1 = RemoveTabs(tbxText1)
tbxText2 = RemoveTabs(tbxText2)
End Sub

Also - you can edit RemoveTabs to replace tabs with multiple spaces if you want to separate the text like a tab would do.

Hope this helps.

by crowmoor

Thanx alot for your code. As I wrote in my comment I woud like to use the tabulator to format text in a report but I understand that its not possible.

Thanxs anyhow

by crowmoor

Thanx for all posting. I see now that I didnt clarify my question but your answers made me think of another solutions. My real intent was to use the tabulator to edit the text so I get to collums of data in one text box when I print the report. Apparently I have to use two fields.

Thanx anyhow.

This discussion is closed to new replies.