validate a value in a form

J

JR

Hi,



I want to control a value in a form

a made a function that works fine in the vbe

when i check the value in a form it always tells me "not ok"

what do i wrong



Jan



Public Function f_CheckNR(sNummer As String) As Boolean

Dim s1 As String, s2 As String, s3 As String

Dim n1 As Double, N2 As Integer

Dim nRest As Integer

'MsgBox sNummer

If Len(sNummer) = 12 Then

s1 = Left(sNummer, 3)

s2 = Mid(sNummer, 4, 7)

s3 = Right(sNummer, 2)



n1 = Val(s1 & s2)

N2 = Val(s3)

nRest = n1 Mod 97

f_CheckNR = (N2 = nRest)

End If

End Function
 
H

hmadyson

I think that a suspect line would be where you say

n1 = Val(s1 & s2)

looking at s1 and s2 they are contiguous so I am guessing that you are
looking at something that has a number for 7 characters, so I would think
that you could just valuse left(snummer, 7). Now the fact that you split them
up makes me think that you are expecting a non-numeric character between
them. If this is the case, i think that you need to change your left and mid
statements to avoid that character.

If this does not make much sense (and it may not) please send a few examples
of input where it does not work.

Please let me know if I can provide more assistance.
 
J

JR

Indeed i can change that but the number is build that way.
however the formula work fine if I use them into vba, vb or vbe.
the error must be on something else

Jan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top