Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005
    Posts
    46

    Unanswered: Double click for next value

    on a table I record IP addresses that start at 192.168.0.4


    so it would like this
    192.168.0.4
    192.168.0.5
    192.168.0.6

    I would like to be able to double click the IP field text box and for the database to say the next ip address availeble is 192.168.0.7 would you like to use this?

    The second thing i would like the code to do is to use any addresses that arnt part of the sequence where they might have been deleted ie if the sequence looked like this

    192.168.0.4
    192.168.0.6

    when double click is applyed the next value should be 192.168.0.5

    any help would be greatley appreciated

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Maybe this bit of ADO code will work. It assumes you've defined the IPAddress field as a string. If you have blank IPAddresses, you need to change the FollowNumber = 4 to the first number matching your first IP address counting in the blank spaces first. Calling this function will return the next value in your string which you can get on your click of the button by using an expression like msgbox " My Next IP = "192.168.0." & NextIPNum. You can also use it in other places or expressions.

    Function NextIPNum() As String
    Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    Dim IP As Integer
    Dim FollowNumber As Integer
    FollowNumber = 4
    Dim strSQL As String
    strSQL = "Select IPAddress from Customers Order By IPAddress Asc"
    rs.Open strSQL, CurrentProject.Connection, adOpenForwardOnly, adLockReadOnly
    If rs.EOF And rs.BOF Then
    MsgBox "No Records"
    rs.Close
    Set rs = Nothing
    Else
    Do While Not rs.EOF
    If IsNull(rs!IPAddress) Or rs!IPAddress = "" Then GoTo Nxt
    IP = CInt(Right(rs!IPAddress, Len(rs!IPAddress) - InStr(rs!IPAddress, "0.") - 1))
    If IP <> FollowNumber Then
    NextIPNum = FollowNumber
    MsgBox "The next IP Avialable is: " & NextIPNum
    rs.close
    set rs = nothing
    Exit Function
    Else
    Nxt:
    FollowNumber = FollowNumber + 1
    rs.MoveNext
    End If
    Loop
    End If
    NextIPNum = FollowNumber
    MsgBox "The next IP Avialable is: " & NextIPNum
    rs.close
    set rs = nothing

    End Function
    Last edited by pkstormy; 10-05-06 at 19:52.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •