Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2308
  • Last Modified:

Access 2010 - tab control within form text box

I have a  large, multi line text box on a form for a NOTES field - bound to a MEMO field.  The user has asked if it is possible to allow TAB key to work within the text box, so he can line up dates and amounts in nice columns - just like he would do in a WORD document.

If he clicks TAB on current form the cursor jumps to the beginning of the text box.

How can I get the TAB key to behave as he has asked?

Thank you.
0
MonkeyPie
Asked:
MonkeyPie
1 Solution
 
Rey Obrero (Capricorn1)Commented:
i don't think that is possible with the normal keyboard keys stroke..
0
 
mbizupCommented:
If the columns are distinct/important, why not use a subform instead, and allow multiple notes, each with an optional date and amount?

So you would have a separate tblNotes with Notes, DateEntered and Amount  as fields, linked by ID to the parent record.
0
 
MonkeyPieAuthor Commented:
Thanks for comments.
Miriam - I am stuck with current design.  My dates and amounts was just a simple example of why they might need the tab key.  The NOTES field is used for all sorts of comments, and sometimes they want it to look nicely formatted.

Carpricorn1 - I also don't think it is poossible, but wondered if someone had a nice workaround.

Suzanne
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
mbizupCommented:
You  *might* be able to use the key down (or keypress) event to test for specific keys such as tab (or some other key) and append a tab  (chr(9)) to the end of the data in the text box.
0
 
MonkeyPieAuthor Commented:
Yes - might try that.  Or I could add some fixed number of space characters to simulate a tab?
0
 
MonkeyPieAuthor Commented:
I added the following code to the keypress event:

Private Sub txtNotes_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then Call cmdCancel_Click
    If KeyAscii = 9 Then
        KeyAscii = 32       ' 32= space
        txtNotes.Text = txtNotes.Text & " **TAB** "
    End If
End Sub

Open in new window

I used **TAB** just for testing purposes.
In the text box, if I type
test followed by the tab character, I get
<space>test**TAB**
but the cursor has jumped to the beginning of the string - where it puts the space char.

So, the TAB character is not being 'overridden' by my if ascii=9 then ascii=32 line.

Close!

But I need to cancel the TAB character after I replace it with **TAB** string, or whatver I eventually replace it with.

Any ideas?
0
 
clarkscottCommented:
Here you go.  This is a little rough.... but work with this a little bit.

In your forms code DECLARATION SECTION:

Dim vback As Boolean

Now, in the memo box - in the KEY DOWN event:

Dim s As String
s = Me.YourMemoBox.Text
If KeyCode = vbKeyTab Then
    s = s & "     "
    Me.YourMemoBox = s
    vback = True
End If


Now, in the next control that gets the focus (next tab order):

In the ON ENTER event:

If vback = True Then
    vback = False
    Me.YourMemoBox.SetFocus
End If


You will have to play with the "selstart" stuff to get your cursor to the end of the text....  but hey, it works.

Scott C
0
 
mbizupCommented:
Sorry for the delay - Thanksgiving.

Your own code is actually pretty close and this is definitely doable in a single event, without letting the focus leave the textbox and forcing it back.

Private Sub TxtNotes_KeyPress(KeyAscii As Integer)
    If KeyAscii = 27 Then Call cmdCancel_Click
    If KeyAscii = 9 Then
        'KeyAscii = 32       ' 32= space
        txtNotes.Text = txtNotes.Text & "         _"
        
        Me.txtNotes.SelStart = Len(Me.txtNotes.Text) - 1
        Me.txtNotes.SelLength = 1
        
    End If
End Sub

Open in new window


The code uses spaces instead of an actual tab, and places an underline at the end so that the position is recognized (trailing spaces or a tab alone are not quite adequate).  The last underline is selected, so it is overwritten by any additional characters typed (but you will have a trailing underline if nothing is typed following a tab.  (You could take care of that with code in the textbox's after update event to remove the underscore if it appears as the last character.)
0
 
mbizupCommented:
Actually you CAN get a true tab in a textbox... not just a approximation using spaces (which is not quite the same thing), but you need one of those numeric keypads on the side of your keboard, or an attached numeric keypad.

- In your table's design set the "Text Format" property of your memo field to Rich Text
- In your form's design, set the Text Format property of your textbox to Rich Text (suprisingly, this is under the Data tab in the property sheet, not the Format tab)
- For a Tab character use Alt-9, using the 9 on the numeric keypad - not the 9 above the letters.  

(The tab appears once you release the Alt key.)
0
 
MonkeyPieAuthor Commented:
Miriam,
That is amazing!  But sadly, I can't change the design of the underlying table - it is used by others.

How on earth did you figure this out?
Suzanne
0
 
mbizupCommented:
Almost blind luck.   I knew the Alt key could be used to enter ascii codes, and had been trying it with my laptop keyboard for this question to no avail.  

My son, coincidentally just showed me today some cool things HE learned how to do with the numeric keypad on the larger keyboard he has attached to his computer... Which automatically made me think of this issue again.

So I've got him to thank for that little trick. :-)

Curious whether it would work with the Text Format setting in the text box alone, without the accompanying setting in the table?  I probably won't have a chance to check that myself before Monday.
0
 
mbizupCommented:
And on a bit of a tangent...  Really showing my age now... That is actually how we created tables, etc in documents in the first word processor I owned.

Alt + some ascii code to insert each segment of double line or corner pieces for outside frames, and underscores, dashes or equals signs for each segment of horizontal line.  Fun, but tedious.
0
 
MonkeyPieAuthor Commented:
I tried the 'rich text' idea on the form text box alone, without changing the bound field and it did not work.  I got a message saying I need to change the underlying field type.

Thank you anyway.  For now I will use the code you posted previously, although it only inserts spaces, so there is still an issue about lining things up nicely.  But better than the native action of TAB which puts cursor back to the beginning.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now