What should I pass into this Function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Barry Wright

    What should I pass into this Function?


    Hi All,

    The error I am getting is 3265:
    "Item not found in this collection."

    How should I be passing in the vReturnFieldNam e so it will be recognized as
    a value in the collection?
    Thanks for your assistance.

    Information:
    I pass four variables to the FindNameString function and want it to return
    the value of field:
    strProjectPrime in table 'Project Primes"

    The table "Project Primes" has two fields
    lngProjectPrime ID and strProjectPrime

    Private Sub TestRun()
    MsgBox FindNameString( "Project Primes", "lngProjectPrim eID",
    "strProjectPrim e", 21)
    End Sub

    Public Function FindNameString( vTblName As String, vFindFieldName As String,
    _
    vReturnFieldNam e As String, vFindFieldValue As Long) As String
    On Error GoTo FindNameString_ Error

    Dim rs As Recordset

    Set rs = CurrentDb.OpenR ecordset(vTblNa me, dbOpenSnapshot)
    If rs.RecordCount > 0 Then
    rs.FindFirst "[" & vFindFieldName & "]=" & vFindFieldValue
    If rs.NoMatch = False Then
    FindNameString = rs![vReturnFieldNam e] 'rs![ProjectPrime]
    Else
    FindNameString = 0
    End If

    End If
    rs.Close
    Set rs = Nothing

    On Error GoTo 0
    Exit Function

    FindNameString_ Error:
    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
    FindNameString of Module Conversion"

    End Function




  • jimfortune@compumarc.com

    #2
    Re: What should I pass into this Function?

    Barry Wright wrote:[color=blue]
    > Hi All,
    >
    > The error I am getting is 3265:
    > "Item not found in this collection."
    >
    > How should I be passing in the vReturnFieldNam e so it will be[/color]
    recognized as[color=blue]
    > a value in the collection?
    > Thanks for your assistance.[/color]

    When I pasted your code into Access, the vTblName just before
    dbOpenSnapshot came in as vTblNa-me. When I removed the hyphen and
    used rs(vReturnField Name) instead of rs![vReturnFieldNam e] it worked.

    James A. Fortune

    Comment

    • Barry Wright

      #3
      Re: What should I pass into this Function?


      Indeed it did work!
      Fantastic James and thank you!

      Barry

      <jimfortune@com pumarc.com> wrote in message
      news:1110314233 .374823.176560@ o13g2000cwo.goo glegroups.com.. .[color=blue]
      > Barry Wright wrote:[color=green]
      > > Hi All,
      > >
      > > The error I am getting is 3265:
      > > "Item not found in this collection."
      > >
      > > How should I be passing in the vReturnFieldNam e so it will be[/color]
      > recognized as[color=green]
      > > a value in the collection?
      > > Thanks for your assistance.[/color]
      >
      > When I pasted your code into Access, the vTblName just before
      > dbOpenSnapshot came in as vTblNa-me. When I removed the hyphen and
      > used rs(vReturnField Name) instead of rs![vReturnFieldNam e] it worked.
      >
      > James A. Fortune
      >[/color]


      Comment

      Working...