Check for a - in a string

Talismanic

Registered User.
Local time
Today, 11:24
Joined
May 25, 2000
Messages
377
I need to check a textbox for a - at the end of a string and if it is not there, add it. So if a number is entered as K433 I need to have Access change it to K433-.

Any ideas?
 
Talismanic, I figured this would be an easy one for you. If this is for data entry, then the code will check the last character in the entry, if it is not a "-", then it will be added.

Private Sub YourTextBox_AfterUpdate()
If Right(Me.ActiveControl, 1) <> "-" Then
Me.ActiveControl = Me.ActiveControl & "-"
End If
End Sub

HTH
RDH

[This message has been edited by R. Hicks (edited 05-08-2001).]
 
Thanks R Hicks, I am huge Cut and Paster when it comes to writing code. It makes development a lot faster but it can make the "coder" lazy and VBA ignorant. Although I have been forcing myself to write much of my code now so I am getting better at it.

Thanks Again!
 
i would use the InStr instead.


Dim intX as integer
intX = instr("XXXXXXXXX")
if intX > 0 then
.....
.....
end if
 
Using the Instr() function would report any "-" in the string. The question was "for a - at the end of a string". So if the string contained a "-" in the middle of the string your approach would give a false result.

RDH

[This message has been edited by R. Hicks (edited 05-17-2001).]
 

Users who are viewing this thread

Back
Top Bottom