Change Input Mask code for ISBN Number field

smercer

Registered User.
Local time
Today, 23:11
Joined
Jun 14, 2004
Messages
442
Hi all

I am trying to make some code to change the input mask for a ISBN Number field when the user presses a key so that it will handle all ISBN numbers.

The problem I am having is it will change on the first key press, but then I have to go into design view, or close form and reopen to make it work again.


Here is my code:
Code:
Private Sub ISBN_Number_KeyUp(KeyCode As Integer, Shift As Integer)

If (Left(Me!ISBN_Number, 1) >= 0 And Left(Me!ISBN_Number, 1) <= 7) Then
    Me!ISBN_Number.InputMask = "0-00-000000-0"
End If
    
End If
If (Left(Me!ISBN_Number, 2) >= 80 And Left(Me!ISBN_Number, 2) <= 94) Then
    Me!ISBN_Number.InputMask = "00-00-00000-0"
End If

If Left(Me!ISBN_Number, 3) >= 950 And Left(Me!ISBN_Number, 3) <= 994 Then
    Me!ISBN_Number.InputMask = "000-00-0000-0"
End If

If Left(Me!ISBN_Number, 4) >= 9950 And Left(Me!ISBN_Number, 4) <= 9989 Then
    Me!ISBN_Number.InputMask = "0000-00-000-0"
End If

If Left(Me!ISBN_Number, 5) >= 99900 And Left(Me!ISBN_Number, 5) <= 99999 Then
    Me!ISBN_Number.InputMask = "00000-00-00-0"
End If

End Sub

I am still working on it and need to do the other different possibilities that I might come across.

I have been doing some research on this and for more info about how the numbers and hypens go together is in the following link.
http://www.isbn.org/standards/home/isbn/international/html/usm4.htm

the end result is to make a calculation to compare the entered number to the check digit and tell the user when they enter an invalid number.

If I don't have the hyphens stored, It would be easier to find the right digit to calculate not to mention less storage needed to store all the hyphens.
 
Wow, you're trying to change the field that you're currently in while making changes within the same field? I would consider using an unbound text box allowing the user to input the first (Left most) numeral and then on Loss of Focus, repaint or refresh the form to update the input box for your [ISBN number] field. Since you are passing the input mask and know what the first numeral will be....you can pass the first charater static and the others with the "0" as place holders.

Also, if you don't nest your IF/THEN/END IF statements or make it a CASE statement, your code is going to run very slowly, as it will have to evaluate all of the cases, even if it meets the criteria of the first.
 

Users who are viewing this thread

Back
Top Bottom