Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access 2010 - tab control within form text box

Posted on 2013-11-27
13
Medium Priority
?
2,219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: 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!

 
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 1500 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

721 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