Setting input mask for IP Address

D

Debbie

How would I set the input value in a form for an Ip
Address setting. I trie 000.000.000.000 but if the ip
address is 154.45.87.8 I get any error message. Thanks to
whom ever can answer this question for me.
 
P

Paul Overway

An input mask does not work well for IP addresses. There are a variety of
conditions that must be met. You really need a validation routine that
analyzes the input. Conditions to be met:

1. Ensure 1st character is not zero, and 2nd too if 1st is zero
2. Ensure that 4 tokens are present
3. Ensure that no token is greater than 255
4. Ensure than all characters are numeric

More to it than you thought, eh?

Nevertheless, if you really want an input mask, see

http://www.mvps.org/access/general/gen0036.htm
 
W

Wayne Morgan

1) Instruct the users to type leading zeros.

2) Use 4 textboxes. Use the OnKeyPress event to check for the period character and move
the focus to the next box when the period is pressed. Place the 4 textboxes with 3 labels
between them that have the periods. To make it all look like one box, set the textboxes
and labels to transparent boarders and backgrounds and flat Special Effect. Place them on
top of a rectangle that matches the formatting used for the form. You may have to use the
Send To Back and Bring To Front commands on the Format menu. Size the background rectangle
to exactly fit the 4 textboxes and 3 labels.
 
D

Dirk Goldgar

Paul Overway said:
This function will analyze an input and determine if it is a properly
formated IP address. It will also correct the input, if it has
leading zero.

Function IsValidIP(Arg As String) As Boolean

On Error Resume Next

Dim i As Integer
Dim intCount As Integer
Dim strTemp As String
Dim strOut As String
Dim strToken As String

'Too many or not enough characters
If Len(Arg) > 15 Or Len(Arg) < 7 Then
Arg = ""
Exit Function
End If

For i = 1 To Len(Arg)
If Mid(Arg, i, 1) = "." Then
intCount = intCount + 1
End If

'Bail if bad character
If InStr("1234567890.", Mid(Arg, i, 1)) = 0 Then
Arg = ""
Exit Function
End If

Next

'Not enough periods
If intCount <> 3 Then
Arg = ""
Exit Function
End If

'Can't start with period
If Mid(Arg, 1, 1) = "." Then
Arg = ""
Exit Function
End If

strTemp = Arg

For i = 1 To 4

If InStr(strTemp, ".") Then
strToken = Mid(strTemp, 1, InStr(strTemp, ".") - 1)
Else
strToken = strTemp
End If

'Empty token...bail
If Len(strToken) = 0 Then
Arg = ""
Exit Function
End If

If CInt(strToken) > 255 Then
'Token too high
Arg = ""
Exit Function
Else
'OK
strOut = strOut & CInt(strToken) & "."
End If

'Lop it for next part
If InStr(strTemp, ".") Then
strTemp = Mid(strTemp, InStr(strTemp, ".") + 1)
End If
Next

strOut = Left(strOut, Len(strOut) - 1)

If strOut = Arg Then
IsValidIP = True
Else
'Arg was bad, but fixable. Return corrected version of Arg
Arg = strOut
IsValidIP = False
End If

End Function

Paul -

Couldn't you streamline that function using the Split() function, if
you're using A2K or later?
 
H

Hugh O'Neill

Wayne said:
1) Instruct the users to type leading zeros.

2) Use 4 textboxes. Use the OnKeyPress event to check for the period
character and move the focus to the next box when the period is
pressed. Place the 4 textboxes with 3 labels between them that have
the periods. To make it all look like one box, set the textboxes and
labels to transparent boarders and backgrounds and flat Special
Effect. Place them on top of a rectangle that matches the formatting
used for the form. You may have to use the Send To Back and Bring To
Front commands on the Format menu. Size the background rectangle to
exactly fit the 4 textboxes and 3 labels.


Adding to this, if you format the four underlying Table Fields to type
Byte, then values higher than 255 are inhibited.

hth

Hugh
 
D

Debbie

Paul thanks for the reply and the web page more help than
you will ever know.
Debbie
 

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