Override event with Function key

CEH

Curtis
Local time
Yesterday, 23:33
Joined
Oct 22, 2004
Messages
1,187
I am attempting to duplicate a feature of some software I use in my office. Been pretty easy so far because this software is built on Access. So here it is...... I have fields with names, job names in this case. Call it "JobDescription" MOST times I will want proper case, so I put ........

Private Sub JobDescription_AfterUpdate()
[JobDescription] = StrConv([JobDescription], vbProperCase)
End Sub

That works fine. But there are times you want to override this code.... The program I am imitating does this by using the "F10" key to move to the next field instead of the tab key. My question is what code to put on the F10 key to skip the "vbProperCase" code??
 
First off, you'll need to create a macro called AutoKeys. In that macro, create an empty line for the function-key F10, because it's default action is to open the menus in your toolbar.

Next, in the code of your form, add following code:

Tekst0 is the field with the propercasing.
Tekst2 is your next field in your form.

Code:
Option Compare Database
Dim ChangeCase As Boolean

Private Sub Form_Load()
'Setting variable to it's default value
ChangeCase = True
End Sub

Private Sub Tekst0_AfterUpdate()
'Checking of the casing needs to be changed
If ChangeCase = True Then
    Me.Tekst0.Value = StrConv(Me.Tekst0.Value, vbProperCase)
End If

'Resetting the value for other records
ChangeCase = True
End Sub

Private Sub Tekst0_KeyDown(KeyCode As Integer, Shift As Integer)
'When F10 is pressed, variable will be set to false so that casing will not change
If KeyCode = vbKeyF10 Then
    ChangeCase = False
End If
End Sub

If this isn't clear enough, check the example attached to this post. In this example, you need to press the F10 key BEFORE leaving the field. That way, the propercase-event will not take place.

Lemme know if it worked!

Greetz,

Seth
 

Attachments

Users who are viewing this thread

Back
Top Bottom