Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2013
    Posts
    5

    Unanswered: Error 2465 - Open Form with OpenArgs

    Can someone tell me what is wrong with this code. Why am I getting an error:
    "Error 2465 Microsoft Access can't find the field 'strLANID' referred to in your expression"

    Private Sub Form_Load()
    'Declare database and recordset objects as variables
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim rst1 As DAO.Recordset
    Dim rst2 As DAO.Recordset
    Dim strLANID As String
    Dim strAskLANID As String
    Dim strMsg As String

    On Error GoTo ErrorHandler

    ' Set the variables to the current database in use and tables
    Set db = CurrentDb()
    Set rst1 = db.OpenRecordset("MYEmployees")
    Set rst1 = db.OpenRecordset("T_EMPLOYEE")
    Set rst2 = db.OpenRecordset("T_EMPLOYEE_INFO")

    'Prompt the user for the Employee's LANID

    strMsg = "Enter Employee's LanID"
    strAskLANID = InputBox(Prompt:=strMsg)
    Debug.Print "strAskLANID = ", strAskLANID

    'Search the T_EMPLOYEE table to see if they already have a record
    'If they do then display the most current record in the form - open in edit mode

    If Not IsNull(DLookup("[LanID]", "T_EMPLOYEE", "[LanID] = '" & strAskLANID & "'")) Then
    strLANID = DLookup("[LanID]", "T_EMPLOYEE", "[LanID] = '" & strAskLANID & "'")
    Debug.Print "strLANID = ", strLANID
    'LanID was found so load the record from the T_EMPLOYEE/T_EMPLOYEEINFO tableS and populate the form
    'Set the forms RecordSource property the the query to select the employee information
    'from the T_EMPLOYEE/T_EMPLOYEEINFO table.
    Me.RecordSource = "qrySelectT_EMPLOYEE"
    Else
    'LanID not found so get the record from the NRCEmployees table and populate the form
    'Set the forms RecordSource property the the query to select the employee information
    'from the NRCEmployees table.
    Debug.Print "strLANID = Not Found in T_EMPLOYEE"
    Me.RecordSource = "qrySelectEmployee"
    End If

    ' Open the form, in edit mode, passing the LANID field to the form
    DoCmd.OpenForm "db.F_EMPLOYEE", OpenArgs:="strLANID"

    rst.Close
    rst1.Close
    rst2.Close

    ExitHere:
    Exit Sub

    ErrorHandler:
    MsgBox "Error is " & Err.Number & " " & Err.Description
    Resume ExitHere
    End Sub

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    With this:
    Code:
    OpenArgs:="strLANID"
    you're passing the litteral string "strLANID" to the form you open.

    To me, it seems that it should be:
    Code:
    OpenArgs:=strLANID
    to pass the value held in the variable strLANID.
    Have a nice day!

  3. #3
    Join Date
    Mar 2013
    Posts
    5
    Sinndho,

    I had that before and got the error so I put it in quotes. I even tried putting in a hardcoded LANID and got the exact same message.

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. What's in strLANID (from the Debug.Print line)?

    2. What does db.F_EMPLOYEE do with it's OpenArgs property?
    Have a nice day!

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    where is strLANID
    when is it populated
    you may have an issue with this as your code is in the form LOAD event
    it may better in the form open event or handled outside the current form
    I'd rather be riding on the Tiger 800 or the Norton

  6. #6
    Join Date
    Mar 2013
    Posts
    5
    1. strLANID contains the user's lanid, i.e. KVM1

    2. I do not know the answer. I'm assuming that is the line that it is complaining about in the error message.

  7. #7
    Join Date
    Mar 2013
    Posts
    5
    healdem,

    I prompt the user for a LANID on the Form Load event. Then I search one table for the lanid, if it there then I want to populate the form.
    If it is not in that table then I want to search a different table and populate the form.
    strLANID gets populated by the DLookup in the IF Then Else statement

  8. #8
    Join Date
    Mar 2013
    Posts
    5
    healdem,

    Also, in my query I have [Forms]![F_EMPLOYEE]![strLANID] in the Criteria for LanID

Posting Permissions

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