List Box Code




I have an Access data project that is connected to a SQL Server 200 database.

I have two forms: Employees and Employee List:

Employee List has a list box on it. In the double click event, I have
placed the following code:

DoCmd.OpenForm "frmEmployees", , , , , , "EmployeeID =" &

On the On Load Event of the Employee Form, I have placed the following code:

Me.EmployeeID = Me.OpenArgs

When I double click on an entry in my list bix, the Employee form opens but
it doesn't navigate to my selected record. Instead, I get the following

Runtime Error '2147352567 (80020009)':
The field EmployeeID is read only.

The employee id field is an Int, Identity field and is the primary key.

Any ideas on what I'm doing wrong.





The openform command line include the following
docmd.OpenForm "Formname",,,WhereCondition,,,OpenArgs

So if you want to open the form with a filter then it should be
DoCmd.OpenForm "frmEmployees", , , "EmployeeID =" & Me.lstEmployees.Column(3)
If you want to pass a parmeter with open args then it should be
DoCmd.OpenForm "frmEmployees", , , , , , Me.lstEmployees.Column(3)
Now about moving to the desire record with the open args use

With Me.RecordsetClone
If .RecordCount > 0 Then
.FindFirst "EmployeeID = " & Me.OpenArgs ' If Employee Number
use that
.FindFirst "EmployeeID = '" & Me.OpenArgs & "'" ' If Employee
String Use that
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End If
End With

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question