Updating record from an unbound list box

L

Leslie J Crouchman

I have a form that has an unbound list box. I wish to update a field of a
table with the bound column of the list box containing ID's. I have tried
using VB and an update query with no success. I can display the ID from the
list box in a text box on the form.

The update query has the code:

forms!FrmFindPerson!lstMembers.Column(2). How should I reference
the list box?

The sensible method should be VB but again the following code I am using
regarding the list box is failing. Can anyone help please?
Private Sub lstMembers_Click()

Dim ID As Long
Dim cbo As Access.ComboBox
Dim lst As Access.ListBox
Dim cnn As ADODB.Connection
Dim rst As New ADODB.Recordset

Dim StrTable As String
Dim strFieldName As String

Dim FrmFindPerson As Form
Set FrmFindPerson = Screen.ActiveForm

ID = Me.lstMembers.Column(2)

'Find and write to the record the ID of the control

'The name of the table
StrTable = "tblInfo"

'The field in the table in which the entry is to be changed
strFieldName = "MasterSN"

Set cnn = CurrentProject.Connection
rst.Open StrTable, cnn, adOpenStatic, adLockReadOnly
rst.MoveFirst
rst.Fields(MasterSN) = Me.lstMembers.Column(2)
This line does not compile.
rst.Update
 

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

Top