You're stuck, I'm afraid. ISBN's are quite variable in terms of the
number of digits between hyphens; and input masks are of very limited
capability.
You can do some validity checking in VBA in the textbox's BeforeUpdate
event, but that's probably about all.
John W. Vinson[MVP] http://www.WysardOfInfo.Com
Remove ^ from EMail address to reply
"Stephen Froehlich" <SFroe...@austin.rr.com> wrote in message news:38BFD585...@austin.rr.com...
This isn't completely accurate -- while the hyphens aren't necessary to distinguish one valid ISBN
from another, they do convey some useful information. The 3 hyphens in an ISBN separate four
distinct parts: the country code, the publisher code, the work sequence number, and the check digit.
For more information, a good starting place is:
http://www.bowker.com/standards/home/isbn/us/
The following routine can be used to validate user-entered ISBN's in Access 2 or later.
Public Function valid_isbn(ByVal in_str As Variant) As Boolean
On Error GoTo err_val_isbn
'
'
' If the input string is a valid ISBN, returns True;
' otherwise, returns False.
'
' Written by Rick Wallace, Wallace Software Corporation
'
'
Dim num_hyphens As Integer
Dim last_hyphen_pos As Integer
Dim cur_pos As Integer
Dim isbn_digits(1 To 9) As Integer
Dim isbn_digits_idx As Integer
Dim isbn_check_digit As Integer
Dim isbn_sum As Long
If IsNull(in_str) Then
' ISBN cannot be null
valid_isbn = False
ElseIf Len(Trim(in_str)) <> 13 Then
' ISBN must have length 13
valid_isbn = False
ElseIf Mid$(in_str, 1, 1) < "0" Or Mid$(in_str, 1, 1) > "9" Then
' 1st ISBN character must be digit
valid_isbn = False
ElseIf Mid$(in_str, 11, 1) < "0" Or Mid$(in_str, 11, 1) > "9" Then
' 11th ISBN character must be digit
valid_isbn = False
ElseIf Mid$(in_str, 12, 1) <> "-" Then
' 12th ISBN character must be hyphen
valid_isbn = False
ElseIf 0 <> StrComp(Mid$(in_str, 13, 1), "X", 0) And (Mid$(in_str, 13, 1) < "0" Or Mid$(in_str,
13, 1) > "9") Then
' 13th ISBN charcter must be digit or uppercase X
valid_isbn = False
Else
' 2nd through 10th ISBN characters must be digits or hyphens; exactly two must
' be hyphens, and the rest digits; the hyphens cannot be consecutive
num_hyphens = 0
last_hyphen_pos = 0
valid_isbn = True ' set o.k.; will set false if error encountered
For cur_pos = 2 To 10
If Mid$(in_str, cur_pos, 1) = "-" Then
If num_hyphens = 2 Or cur_pos = last_hyphen_pos + 1 Then
valid_isbn = False
Exit For
Else
last_hyphen_pos = cur_pos
num_hyphens = num_hyphens + 1
End If
ElseIf Mid$(in_str, cur_pos, 1) < "0" Or Mid$(in_str, cur_pos, 1) > "9" Then
valid_isbn = False
Exit For
End If
Next cur_pos
If valid_isbn Then
If num_hyphens <> 2 Then
valid_isbn = False
Else
' ISBN digits, multiplied by decreasing integers starting with 10 and
' summed, must be divisible by 11
isbn_digits_idx = 1
For cur_pos = 1 To 11
If Mid$(in_str, cur_pos, 1) <> "-" Then
isbn_digits(isbn_digits_idx) = CInt(Mid$(in_str, cur_pos, 1))
isbn_digits_idx = isbn_digits_idx + 1
End If
Next cur_pos
If Mid$(in_str, 13, 1) = "X" Then
isbn_check_digit = 10
Else
isbn_check_digit = CInt(Mid$(in_str, 13, 1))
End If
isbn_sum = 0
For isbn_digits_idx = 1 To 9
isbn_sum = isbn_sum + (isbn_digits(isbn_digits_idx) * (11 - isbn_digits_idx))
Next isbn_digits_idx
isbn_sum = isbn_sum + isbn_check_digit
If isbn_sum Mod 11 <> 0 Then
valid_isbn = False
End If
End If
End If
End If
Exit Function
err_val_isbn:
MsgBox Error$, vbOKOnly + vbCritical, "valid_isbn"
valid_isbn = False
Exit Function
End Function
Rick Wallace wrote:
>
> The following routine can be used to validate user-entered ISBN's in Access 2 or later.
>
> Public Function valid_isbn(ByVal in_str As Variant) As Boolean
> ...