To do it this way, you'll have to create an event procedure for the
BeforeUpdate event of the control. Open the control properties and go to the
events tab, find before update, and click the dropdown list on the side to
select Event Procedure. This should open the vba window, with these two
lines already there for you:
Private Sub YourControl_BeforeUpdate(Cancel As Integer)
End Sub
You'll put your code inside these two lines. There's a few things you
should probably add in here, keeping in mind scenarios such as no data being
entered, or a "-" already being in there, so we'll modify my previous example
a bit to account for this.
Here's what you'll end up with:
Private Sub YourControl_BeforeUpdate(Cancel As Integer)
Dim strValue As String
'Check and make sure the control has a value
If Nz(Me.YourControl, "") <> "" Then
'Get rid of any "-" already there
strValue = Replace(Me.YourControl, "-", "")
'Get all the characters except the last one
strValue = Mid(Me.YourControl, 1, Len(Me.YourControl) - 1)
'Add the "-" at the end
strValue = strValue & "-"
'Uppercase the last character of the control and add it
strValue = strValue & UCase( _
Mid(Me.YourControl, Len(Me.YourControl) - 1, 1))
'Check the value of strValue (it should be what you want)
'Open the Immediate Window to see what the statement is
Debug.Print strValue
'Apply this as the new value of the control
Me.YourControl = strValue
End If
End Sub
I haven't tested it, but I think it should be pretty close. Change any
YourControl you see to the name of your control.
For the record, using an input mask may be much easier if you are not
familiar with VBA and the various conditions to be aware of. I prefer not to
use input masks for my own reasons, but there's not real reason not to.
hth
Oh yea... don't forget to add at least some basic error handling
--
Jack Leach
www.tristatemachine.com
- "Success is the ability to go from one failure to another with no loss of
enthusiasm." - Sir Winston Churchill