Wildcards (1 Viewer)

CBragg

VB Dummy
Local time
Today, 07:42
Joined
Oct 21, 2002
Messages
89
Im trying to validate a number field in VB so the users can only enter either .00, .25, .50, .75 With any number before the decimal space.

e.g. if they enter 4.25 nothing happens, however if they enter 4.30 then a msgbox appears.

Ive tried all the logical ideas i can think of:

<> "*.25"
<> "#.25"
<> "?.25"
<> Chr(42) & ".25"

Where do i go from here?

Any sort of help would be appreciated.

Cheers
 
D

DJN

Guest
It looks as though the numbers are text. If so, this piece of code will help.

Private Sub FieldName_BeforeUpdate(Cancel As Integer)


If (Right(Me.FieldName, 3) <> ".00") And (Right(Me.FieldName, 3) <> ".25") And (Right(Me.FieldName, 3) <> ".50") And (Right(Me.FieldName 3) <> ".75") Then

MsgBox "wrong input "

Exit Sub

End If


End Sub

This also assumes that the number has 2 digits after the decimal point.


David
 

CBragg

VB Dummy
Local time
Today, 07:42
Joined
Oct 21, 2002
Messages
89
Sorry, but that doesnt work. My numbers are numeric, double and fixed.

Cheers for trying though

Any other ideas?
 

geralf

Registered User.
Local time
Today, 07:42
Joined
Nov 15, 2002
Messages
212
Try this;


Private Sub FieldName_BeforeUpdate(Cancel As Integer)

Dim lngNumber as Long
lngNumber=Me.FieldName*100

If lngNumber Mod 25 <> 0 Then
MsgBox "wrong input "
Cancel = True
End If
Exit Sub

Haven't tried it, but I think it will work!
 
Last edited:

CBragg

VB Dummy
Local time
Today, 07:42
Joined
Oct 21, 2002
Messages
89
Sorry, that doesnt work either. Could it be that im doing this on the AfterUpdate event instead of the BeforeUpdate.

Any other ideas would be greatly appreciated.

Cheers anyway.
 

geralf

Registered User.
Local time
Today, 07:42
Joined
Nov 15, 2002
Messages
212
Yes, it should be placed in the before update event. I'm trying it out now just to test it. I'll post back.
 

CBragg

VB Dummy
Local time
Today, 07:42
Joined
Oct 21, 2002
Messages
89
Should this be in the beforeUpdate event of the actual text box im trying to validate, or the next tabbed text box?

Cheers for this.
 

geralf

Registered User.
Local time
Today, 07:42
Joined
Nov 15, 2002
Messages
212
I've just tried it out, and it works as it should. It must be placed in the Before Update Event of the text box control you are validating.
 

CBragg

VB Dummy
Local time
Today, 07:42
Joined
Oct 21, 2002
Messages
89
I cant get this to work at all, also if its in the BeforeUpdate event how will it validate it after the user has typed the value in??

This is maybe just me being stupid, ive had a hard morning!!
 

geralf

Registered User.
Local time
Today, 07:42
Joined
Nov 15, 2002
Messages
212
Here is the exact code I'm using. Copy and paste the code int your BeforeUpdate Event of the control. Remember to change the name of the Me.MyNumberfield to your controls name. Post back if you still have problems.

Dim lngNumber As Long
lngNumber = Me.MyNumberField * 100
If lngNumber Mod 25 <> 0 Then
MsgBox "wrong input "
Cancel = True
End If
 

Users who are viewing this thread

Top Bottom