Synchronize List Box with Form

G

Guest

I would like to synchronize an unbound list box with a bound form. The data
in the list box and the form are the same. I am able to synchronize the form
to the list box through the form's current property (ie. Me!ListBoxID =
Me!TextboxID) where the form's text box field and list box value are the
same. However, I cannot click on a record in the list box and have the form
synchronize to that record. Is this possible?
 
D

Dale Fye

Sure,

In the Click event of the list box, you will need a little bit of code.
Basically, what this does is creates a recordset from the same source as
your form. It then finds the first value of the ID field that matches the
value of the ID field in your listbox. It then sets the bookmark property
of the form to that of the record in the recordset that matches your listbox
selection. Since it clones the recordset of the form, the bookmark property
of the rs will be the same as the bookmark property of the form.

Private Sub ListBoxID_Click()

Dim rs as dao.recordset
Set rs = me.RecordSetClone

With rs
.findfirst "ID = " & me.ListBoxID
If .NoMatch
msgbox "Something is wrong! This should have worked"
Else
me.bookmark = rs.bookmark
Endif
End with
rs.close
set rs = nothing

End sub

HTH
Dale
 
G

Guest

Thank you Dale, I know that procedure, and am not sure why I didn't think of
it, but it worked just fine.

Skennelly
 

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