I'd use an input mask on your form field
Unfortunately this accepts spaces in addition to numbers so you'll need to fix up the spaces. In the after update event call something like this
Code:
Function FixIPAddress(str As String) As String
'trim out spaces in an ip address
Dim v As Variant
Dim temp As String
Dim i As Long
v = Split(str, ".")
For i = LBound(v) To UBound(v)
temp = temp & Trim$(v(i)) & "."
Next i
If Len(temp) > 0 Then
temp = Left$(temp, Len(temp) - 1)
End If
FixIPAddress = temp
End Function
Then you'll want to check that it's a valid ip address. Something like this might work
Code:
Function IsValidIPAddress(str As String) As Boolean
'return true if valid ip address
'assumes basic quad notation
Dim v As Variant
Dim i As Long
Dim temp As Boolean
v = Split(str, ".")
For i = LBound(v) To UBound(v)
temp = (CInt(v(i)) >= 0 And CInt(v(i)) <= 255)
If Not temp Then Exit For
Next i
IsValidIPAddress = temp
End Function
So, all put together you'd see something like this:
Code:
Private Sub Text1_AfterUpdate()
Me.Text1 = FixIPAddress(Me.Text1)
if not IsValidIPAddress(me.text1) then
MsgBox "Input Values not Valid?"
me.Text1.SetFocus
end if
End Sub