UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Memo Field/disable Tab Key, Access 2007    
 
   
johan
post Oct 15 2019, 07:05 AM
Post#1



Posts: 1,026
Joined: 24-April 08
From: Riebeek Kasteel, Western Cape, South Africa


I have the following code in my Memo field KeyDown property. I want the TAB key be disabled when a user enter into the memo field. As it sometime happens that a user, after entering data, accidentally press the TAB key, losing all data entered, instead of the Enter key for a new line

CODE
Private Sub Amendment_KeyDown(KeyCode As Integer, Shift As Integer)
Dim CursorPosition As Integer
    Dim NumberOfCrLfsInSelected As Integer
    Dim FirstHalf As String
    Dim SecondHalf As String
        
    If KeyCode = vbKeyTab And Me.ActiveControl.Name = "Amendment" Then
        Me.Painting = False
        CursorPosition = Me.Amendment.SelStart
'        FirstHalf = Left(Me.Amendment.Text, CursorPosition)
'        SecondHalf = Mid(Me.Amendment.Text, CursorPosition + 1)
        Me.Amendment = FirstHalf & "    " & SecondHalf
        Me.Amendment.SelStart = CursorPosition + 4
        KeyCode = 0
        Me.Painting = True
    End If

End Sub

--------------------
Johan
Winners don't do different things, they do things different.
Go to the top of the page
 
isladogs
post Oct 15 2019, 08:50 AM
Post#2


UtterAccess VIP
Posts: 1,825
Joined: 4-June 18
From: Somerset, UK


Make sure KeyPreview is set to Yes in the Other tab of the Form property sheet otherwise the key remapping will not work correctly.

I would disable vbKeyTab before users have a chance to click it.
In other words don't use 'if Keycode=vbkeytab….'
You could do that for the form as a whole in the Form_load event.
However if you want to allow it elsewhere , try using the SetFocus event for that control.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
missinglinq
post Oct 15 2019, 10:13 AM
Post#3



Posts: 4,640
Joined: 11-November 02



For this to happen the Memo Field has to be the last Control on the Form to get Focus... and the entered Data doesn't 'disappear.' The Tab key is simply moving to the next Record.

To stop this behavior, simply, in Form Design View...go to Properties - Other and change the Cycle Property from 'All Records' to 'Current Record,' and the current Record will still be there...along the data already entered in the Memo Field!

Linq ;0)>
This post has been edited by missinglinq: Oct 15 2019, 10:14 AM

--------------------
Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
isladogs
post Oct 15 2019, 12:05 PM
Post#4


UtterAccess VIP
Posts: 1,825
Joined: 4-June 18
From: Somerset, UK


Having read Linq's answer, I agree completely.

In fact, clicking Tab or Enter have the same effect.
If its the last control in the tab order, both move you to the next record.
Otherwise, both move you to the next control in the tab order.

So on reflection I think your code is pointless … unless you disable the Enter key as well

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 
johan
post Oct 16 2019, 01:24 AM
Post#5



Posts: 1,026
Joined: 24-April 08
From: Riebeek Kasteel, Western Cape, South Africa


Thanks Guys

--------------------
Johan
Winners don't do different things, they do things different.
Go to the top of the page
 
missinglinq
post Oct 16 2019, 05:57 AM
Post#6



Posts: 4,640
Joined: 11-November 02



Glad we could help!

Linq ;0)>

--------------------
Hope this helps!

The problem with making anything foolproof...is that fools are so darn ingenious!

All posts/responses based on Access 2003/2007
Go to the top of the page
 
johan
post Oct 16 2019, 06:15 AM
Post#7



Posts: 1,026
Joined: 24-April 08
From: Riebeek Kasteel, Western Cape, South Africa


Just a question if my code means nothing than how can I get it to work in the memo field.

--------------------
Johan
Winners don't do different things, they do things different.
Go to the top of the page
 
isladogs
post Oct 16 2019, 07:55 AM
Post#8


UtterAccess VIP
Posts: 1,825
Joined: 4-June 18
From: Somerset, UK


As already mentioned you could disable both Tab and Enter for this particular control or the form as a whole.
However doing that might disable functionality that you need.

Alternatively, perhaps have a message popup when either key is pressed asking the user whether they really want to move to the next record/control.
If user says no, then cancel key press action.

--------------------
Colin (Mendip Data Systems)
Website, email
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    20th November 2019 - 10:10 AM