invalid use of null

B

blackcat

I have the following code which checks the ISBN check digit to ensure a
correct ISBN no is enter for a product. This works fine, however, if the
user enters the field and then decideds not to enter an isbn no, i get the
'Invalid Use of Null' error message which will not go away and even takes the
user into the code, which i don't want. Could anyone please tell me how to
stop this happening, i've tried setting the strnumer as variant but this
doesn't work.

Private Sub LinkISBN_Exit(Cancel As Integer)

varMultiplier = Array(Null, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3)

'Dim strnumber As Variant

strnumber = [LinkISBN]
'strnumber = format(dwisbn, "000000000")


dwchecksum = 0
total = 0
'checkno = CInt(Mid(strnumber, 10, 1))
checkno = Mid(strnumber, 13, 1)
msg = "Incorrect ISBN Please Re-Enter"




For p = 1 To Len(strnumber)

'wdigit = CInt(Mid(strnumber, p, 1))
wdigit = Mid(strnumber, p, 1)
If p >= 1 And p <= 12 Then
dwchecksum = wdigit * varMultiplier(p)
total = total + dwchecksum
End If

'If p = 10 And [wdigit] <> "X" Then

'dwchecksum = wdigit * varMultiplier(p)
'total = total + dwchecksum
'End If

[tot] = total


Next p

[modfig] = [tot] Mod 10
[check] = 10 - [modfig]
If [modfig] = 0 Then
[check] = 0
End If

If [modfig] = 1 Then
[check] = "X"
End If
check = LTrim(check)

If check <> checkno Then
MsgBox (msg)

End If


End Sub
 
S

Stefan Hoffmann

hi blackcat,
I have the following code which checks the ISBN check digit to ensure a
correct ISBN no is enter for a product.
Caution:

The ISBN system was changed 2005, they added a new type of ISBN, see

http://en.wikipedia.org/wiki/Isbn
user enters the field and then decideds not to enter an isbn no, i get the
'Invalid Use of Null' error message which will not go away and even takes the
user into the code, which i don't want. Could anyone please tell me how to
stop this happening, i've tried setting the strnumer as variant but this
doesn't work.
First of all, make it a separate function:

Public Function IsValidIsbn(AIsbn As String) As Boolean

'your code..

End Function

Then allways name your controls, don't use the default given names. So
call your TextBox bound to [LinkISBN] txtLinkIsbn.
Private Sub LinkISBN_Exit(Cancel As Integer)

Cancel = False
If Not IsNull(txtLinkIsbn.Value) Then
If Not IsValidIsbn(txtLinkIsbn.Value) Then
Cancel = True
End If
Else
Cancel = True
End If



mfG
--> stefan <--
 
B

blackcat

I'm sorry, i don't understand what you mean by a seperate function - do i set
this up as a module and then call that? thanks for your help with this

Stefan Hoffmann said:
hi blackcat,
I have the following code which checks the ISBN check digit to ensure a
correct ISBN no is enter for a product.
Caution:

The ISBN system was changed 2005, they added a new type of ISBN, see

http://en.wikipedia.org/wiki/Isbn
user enters the field and then decideds not to enter an isbn no, i get the
'Invalid Use of Null' error message which will not go away and even takes the
user into the code, which i don't want. Could anyone please tell me how to
stop this happening, i've tried setting the strnumer as variant but this
doesn't work.
First of all, make it a separate function:

Public Function IsValidIsbn(AIsbn As String) As Boolean

'your code..

End Function

Then allways name your controls, don't use the default given names. So
call your TextBox bound to [LinkISBN] txtLinkIsbn.
Private Sub LinkISBN_Exit(Cancel As Integer)

Cancel = False
If Not IsNull(txtLinkIsbn.Value) Then
If Not IsValidIsbn(txtLinkIsbn.Value) Then
Cancel = True
End If
Else
Cancel = True
End If



mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
I'm sorry, i don't understand what you mean by a seperate function - do i set
this up as a module and then call that? thanks for your help with this
Yup.


mfG
--> stefan <--
 
B

blackcat

sorry to be a pain but how do i do this? i've set up a module called
IsValidIsbn, then on the LinkIsbn field on exit event procedure i've typed in

Private Sub LinkISBN_Exit(Cancel As Integer)

Call IsValidIsbn

End Sub

and i get the error 'compile error expected variable or procedure, not module'
 
S

Stefan Hoffmann

hi,
sorry to be a pain but how do i do this? i've set up a module called
IsValidIsbn, then on the LinkIsbn field on exit event procedure i've typed in
Private Sub LinkISBN_Exit(Cancel As Integer)

Call IsValidIsbn
As you have named the module and the function using the same name, this
must be:

Cancel = Not IsValidIsbn.IsValidIsbn(Nz([LinkIsbn], ""))
and i get the error 'compile error expected variable or procedure, not module'
Read my first posting again.


mfG
--> stefan <--
 

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