Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2002
    Location
    Hamilton,Ontario
    Posts
    132

    Question Unanswered: Search for Highest ID in table

    Hi all
    im trying to fetch the Highest [Work Order ID] from this table , but its not working properly . any one knows wahts wrong wit this code.

    Public Function fetchWOID() As Integer
    'I added this portion Faisal Shah
    If ErrorTrapping = True Then
    On Error GoTo fetchWOID_Err_Handler
    End If
    Dim x As Integer
    Dim maxx As Integer
    Dim minx As Integer
    Dim currentx As Integer
    Dim curdb As Database
    Set curdb = CurrentDb
    With curdb.OpenRecordset("Inventory WorkOrder")
    For x = 0 To .RecordCount - 1
    currentx = .Fields("Work Order ID").Value
    If currentx > maxx Then
    maxx = currentx
    End If
    .MoveNext
    Next x
    MsgBox maxx
    End With
    curdb.Close
    Set curdb = Nothing
    Exit Function
    fetchWOID_Err_Handler:
    DispError "Fetching Work Order ID", "yworkOrder2"
    Exit Function
    End Function


    thanx in advance

  2. #2
    Join Date
    Apr 2003
    Location
    Santa Barbara, CA
    Posts
    67

    Re: Search for Highest ID in table

    Originally posted by VBAPROGRAMMER
    Hi all
    im trying to fetch the Highest [Work Order ID] from this table , but its not working properly . any one knows wahts wrong wit this code.

    Public Function fetchWOID() As Integer
    'I added this portion Faisal Shah
    If ErrorTrapping = True Then
    On Error GoTo fetchWOID_Err_Handler
    End If
    Dim x As Integer
    Dim maxx As Integer
    Dim minx As Integer
    Dim currentx As Integer
    Dim curdb As Database
    Set curdb = CurrentDb
    With curdb.OpenRecordset("Inventory WorkOrder")
    For x = 0 To .RecordCount - 1
    currentx = .Fields("Work Order ID").Value
    If currentx > maxx Then
    maxx = currentx
    End If
    .MoveNext
    Next x
    MsgBox maxx
    End With
    curdb.Close
    Set curdb = Nothing
    Exit Function
    fetchWOID_Err_Handler:
    DispError "Fetching Work Order ID", "yworkOrder2"
    Exit Function
    End Function


    thanx in advance

    DMax(expr, domain[, criteria])
    DMin(expr, domain[, criteria])

    maxx = dmax("Work Order ID","Inventory WorkOrder")
    minx = dmin("Work Order ID","Inventory WorkOrder")

  3. #3
    Join Date
    Nov 2002
    Location
    Hamilton,Ontario
    Posts
    132

    Re: Search for Highest ID in table

    here is the workign code which fetches the highest id .
    Thanx for Your help. I really appreciate that


    Option Compare Database
    Option Explicit
    Global maxx As Long
    Public Function fetchWOID()
    'I added this portion Faisal Shah
    If ErrorTrapping = True Then
    On Error GoTo fetchWOID_Err_Handler
    End If
    Dim x As Long
    Dim adrs As Recordset
    Dim currentx As Long
    Dim curdb As Database
    Set curdb = CurrentDb
    Set adrs = curdb.OpenRecordset("Inventory WorkOrder")
    Do Until adrs.EOF
    currentx = adrs.Fields("Work Order ID").Value
    If currentx > maxx Then
    maxx = currentx
    End If
    adrs.MoveNext
    Loop
    adrs.Close
    Set adrs = Nothing
    curdb.Close
    Set curdb = Nothing
    Exit Function
    fetchWOID_Err_Handler:
    DispError "Fetching Work Order ID", "yworkOrder2"
    Exit Function
    End Function

Posting Permissions

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