Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tab Event Problem

Status
Not open for further replies.

WOTRAC

MIS
Nov 22, 2002
36
GB

I have a form with a memo field. The user wishes to enter text with a mixture of spaces, carriage returns and tabs.

Problem is when you use the tab key it exits the field.
I have considered using an alternative key ( say F12) but am unsure how to go about it, as my vba skills are limited.

Could anyone help, or maybe suggest an alternative method.

Please



 
I don't think you can do this using a regular text box control. When you need formatting capabilities the best control is the Rich Text Box control. To add tabs, trap the keystroke like this:

Code:
Private Sub rtfMemo_KeyDown(KeyCode As Integer, ByVal Shift As Integer)
  If KeyCode = vbKeyTab Then
    Dim lngSel As Long
    With Me.rtfMemo.Object
      lngSel = .SelStart
      .Text = .Text & Chr(9)
      .SelStart = lngSel + Len(Chr(9))
    End With
    KeyCode = 0
  End If
End Sub
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
I don't appear to have a rich text box control in
Microsoft Access 2000.
Or am I mistaken

Paul
 
The rtf control comes with VB or Access Developer, but I did manage to find a way to do it with a standard Access textbox:

Code:
Private Sub MemoText_KeyDown(KeyCode As Integer, Shift As Integer)
  If KeyCode = vbKeyTab Then
    SendKeys Space(4)
    KeyCode = 0
  End If
End Sub

"Necessity is the mother of invention..." [worm]
VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Brilliant!!

By the way I did manage to get the rich text box to work as I have a copy of vb 6.0

Only one problem, how do you convert the rich text back to plain text before saving it in the Access database.


Thanks
 
The rtf control's 'Value' (rtfControl.Value) will contain all the formatting tags in addition to the text, and if you bind it to a field that's what you'll store in the table.

If you just need the text without formatting, you could copy the text into another memo field in the Before_Update() event of the control using:
Code:
 [myMemoField] = rtfControl.Ojbect.Text

which returns the ascii text. Having 2 memo fields per record could get rather large over time, so you might just use a regular text box if you're not interested in bold or colored text, etc.

VBSlammer
redinvader3walking.gif

Unemployed in Houston, Texas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top