Syncing list box selected item

R

ruth

I'm creating a search form based on a table of organizations (fields:
orgcode, orgname). The form has a textbox control that shows the orgcode and
a listbox control that shows the orgname - this is set to allow only one
orgname to be selected. The idea is that a user can search on the orgcode or
use the listbox to find the organization name.

What I'd like to do is have the orgname that is displayed as selected in the
list box correspond to the orgcode. Of course, if the user clicks in the
listbox this occurs as a matter of course. However, I also want this to
occur when the user does a search on orgcode.

Here's my code:

Private Sub cmdFindCode_Click()
On Error GoTo Err_cmdFindCode_Click

Dim rs As DAO.Recordset
Dim rnum As Integer

txtCode.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Set rs = Me.lstOrgName.Recordset
rs.FindFirst "[ORGCODE] =" & txtCode.Value
rnum = rs.AbsolutePosition
Set rs = Nothing
lstOrgName.Selected(rnum) = True

Exit_cmdFindCode_Click:
Exit Sub

Err_cmdFindCode_Click:
MsgBox Err.Description
Resume Exit_cmdFindCode_Click

End Sub

This generates the error message "Update or CancelUpdate without AddNew or
Edit".

Any help would be greatly appreciated.
 
Top