Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

Error 2465 - Open Form with OpenArgs

$
0
0
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" :confused:

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

Viewing all articles
Browse latest Browse all 13329

Trending Articles