Solved

Access 2010 - tab control within form text box

Posted on 2013-11-27
13
1,886 Views
Last Modified: 2013-11-29
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
Comment
Question by:MonkeyPie
13 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39682374
i don't think that is possible with the normal keyboard keys stroke..
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39682494
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
 

Author Comment

by:MonkeyPie
ID: 39682569
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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 61

Expert Comment

by:mbizup
ID: 39682671
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
 

Author Comment

by:MonkeyPie
ID: 39682676
Yes - might try that.  Or I could add some fixed number of space characters to simulate a tab?
0
 

Author Comment

by:MonkeyPie
ID: 39682699
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
 
LVL 20

Expert Comment

by:clarkscott
ID: 39685016
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
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39685513
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
 
LVL 61

Expert Comment

by:mbizup
ID: 39686306
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
 

Author Comment

by:MonkeyPie
ID: 39686314
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
 
LVL 61

Expert Comment

by:mbizup
ID: 39686380
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
 
LVL 61

Expert Comment

by:mbizup
ID: 39686388
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
 

Author Closing Comment

by:MonkeyPie
ID: 39686391
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question