Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validate user entry as currency

Status
Not open for further replies.

Pulser

Programmer
Apr 26, 2002
3
0
0
GB
I can force all entry to be numeric using:

Private Sub txtTravel_Total_Cost_PressKey()
' Ensure entered value is numeric
KeyAscii = IIf(Not KeyAscii = 8 And Not IsNumeric(Chr (KeyAscii)), 0, KeyAscii)
End Sub

This will not work for currency values and there is'nt any IsCurrency() function!!

Anyone came across this or use a simple get around??
 
In the text box keydown event, Pass in the textbox and keycode to the procedure below
Ex. call gFormatToCurrency(txtTravel_Total_Cost, keycode)

Public Sub gFormatToCurrency(pTextbox As TextBox, pKeycode As Integer)
Dim lNum As String
Dim lLength As Integer
Dim lInput As String

If pKeycode = 16 Then Exit Sub
If pTextbox.SelLength > 0 And pKeycode <> 13 Then
pTextbox.Text = &quot;&quot;
End If
lInput = pTextbox.Text
Select Case pKeycode
Case vbKey0, 96
lNum = &quot;0&quot;
Case vbKey1, 97
lNum = &quot;1&quot;
Case vbKey2, 98
lNum = &quot;2&quot;
Case vbKey3, 99
lNum = &quot;3&quot;
Case vbKey4, 100
lNum = &quot;4&quot;
Case vbKey5, 101
lNum = &quot;5&quot;
Case vbKey6, 102
lNum = &quot;6&quot;
Case vbKey7, 103
lNum = &quot;7&quot;
Case vbKey8, 104
lNum = &quot;8&quot;
Case vbKey9, 105
lNum = &quot;9&quot;
Case vbKeyBack 'Backspace
lNum = &quot;&quot;
lLength = Len(lInput)
lInput = Left$(lInput, lLength - 1)
pTextbox.Text = lInput
pTextbox.SelStart = Len(pTextbox.Text)
Exit Sub
Case Else
Beep
Exit Sub
End Select
pTextbox.Text = lInput & lNum
pTextbox.SelStart = Len(pTextbox.Text)
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top