List box problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I created a form using the form Wizard. After creating the form I edited the
properties of the form. I then added a list box. The problem is, every time
I search or click on a number within the box it edits The current record and
changes information. Is there any way that I can look up the record. Based
on what I click within the combo box without actually changing the record.
Can I have some type of command button that will allow me to look up the
record without changing it and then they be pressing to toggle button I can
change to edit mode.
 
Not sure I understand exactly what you are trying to do but I'll take a stab
at it anyway. I think the list box should be unbound first of all. Where ever
you are retrieving the values from I think will then be used as a criteria
for a where clause at some other point such as in a command button.
 
Rusty,

It sounds like your listbox is bound to a field in the Recordsource
table/query of the form. Select the control and then check the ControlSource
property of the listbox. If you find a fieldname there it is bound and this
means that whatever value is selected in the listbox will be saved in that
field.

An unbound listbox or combo is used for record navigation. While you could
create additional controls and logic to toggle a single control between
being bound and unbound, I personally think this makes for a confusing
interface.

Here's what you need to accomplish the record navigation (make the record
with the key matching the selected value the current record). Create your
unbound listbox. Make sure the bound column of the list/combo is the primary
key field for your table. In the AfterUpdate event of the listbox you would
have the following code:

with me.recordsetclone
.findfirst "PrimaryKey=" & me.lstPrimaryKey
if not .nomatch then
me.bookmark=.bookmark
endif
end with

Replace "PrimaryKey" with the name of the primary key field in the forms
Recordsource and replace "lstPrimaryKey" with the name of the listbox
control.

If the Primary key field is text you will need to revise the findfirst line
to wrap the value coming from the unbound listbox in quotes. This is easily
done by putting a pair of quote characters everywhere a quote character
should appear. Note that there are 3 quotes (") before the first & and 4
quotes after the second &


..findfirst "PrimaryKey=""" & me.lstPrimaryKey & """"
 
Back
Top