listbox selected(0) causing error Error 3020

G

Guest

I have a reminder form that has a listbox (ListUnrecOnEmployee) that displays
3 columns that is populated by sql. Each row contain values that coinside
with some of the fields on the current record. The onclick for this
listbox(ListUnrecOnEmployee) has a findrecord command so the user can quickly
move between the queried records. I have another listbox(ListOrderedItems)
for the items ordered that populates based on the current ID of the form.
The onCurrent event of the form will requery that control to update it. All
of this works as expected. I then thought it would be nice for the users if
listbox1 would be highlight on the current record based on the current
record. I thought it was working fine until I closed it and reopened it,
then I got this error when I click on either of the listboxs - Update or
CancelUpdate without AddNew or Edit. (Error 3020). So I opted out the line
of code and the error goes away. I have included the code to help. I have
searched the web for help and have not found anything that has helped. I
believe it is probably something that I have wrong and would greatly
appreciate any input you may have.

Code on the first listbox(ListUnrecOnEmployee)
Private Sub ListUnrecOnEmployee_Click()

Dim intGoToPORec As Integer
intGoToPORec = Me.ListUnrecOnEmployee.Column(0)
Me.POID.SetFocus
DoCmd.FindRecord intGoToPORec, , , , , , True
End Sub

Code for the Form onCurrent
Private Sub Form_Current()

Me.ListOrderedItems.Requery
Dim lngPOCRec As Long
lngPOCRec = (Me.CurrentRecord) - 1

'Me.ListUnrecOnEmployee.Selected(lngPOCRec) = True 'opted out error 3020

End Sub
 
G

Guest

I found that if I used this, I could achieve the desired result. Would still
appreciate your input on this.

Private Sub Form_Current()
Me.ListOrderedItems.Requery
Dim lngPOCRec As Long
lngPOCRec = (Me.CurrentRecord) - 1

Me.ListUnrecOnEmployee.SetFocus
Me.ListUnrecOnEmployee.ListIndex = lngPOCRec

End Sub
 

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