Re: Set Focus & 2108 error
- From: "Dirk Goldgar" <dg@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 23 Apr 2005 16:35:50 -0400
"dave h" <none@xxxxxxxx> wrote in message
news:OecHvQDSFHA.244@xxxxxxxxxxxxxxxxxxxx
> Hi,
>
> This is just an FYI for anyone who may have lost as much time as I
> did with this set focus issue. The case is this:
>
> You have 2 list boxes and you want to update the 2nd one when a user
> selects a row in the first one. However, lets say for some reason
> you want to have a particular row selected/highlighted in the 2nd
> list box. Further, lets say that "list2 = list2.itemdata(somevalue)"
> does not work because you don't have a column in the list box that is
> always unique. This bit of code will select the first bound column
> that matches - but that may not be the row you want. Or, your case
> my be more like mine where I was trying to iterate through the list
> box to develop some totals.
>
> The most direct approach is to use listIndex and set it to the row
> you want. However, you must set focus first. Here is where the
> problem comes in. I get getting this miserable 2108 error.
>
> The problem started because I would select my list box event in the
> VBA dropdown event list and use the default "before" update event.
> For whatever reason, using the before update for the 1st list box,
> screws up trying to set focus on the 2nd list box. Here is the code:
>
> Private Sub Form_Load()
> List1.RowSource = "select * from table1"
> End Sub
>
> Private Sub List1_AfterUpdate() 'this works
> fine List2.RowSource = "select * from table2"
> List2.SetFocus
> List2.ListIndex = 1
> End Sub
>
> Private Sub List1_BeforeUpdate(Cancel As Integer)
> ' it you put the above code in here you will get a 2108 runtime error
> End Sub
>
> Maybe I'm the only person in the world who used the default "before"
> and got into this mess - but, if there is a similar dummy out there,
> this might save you some time.
Is there some reason you wouldn't just write
Me!List2.Selected(1) = True
?
--
Dirk Goldgar, MS Access MVP
www.datagnostics.com
(please reply to the newsgroup)
.
- Follow-Ups:
- Re: Set Focus & 2108 error
- From: dave h
- Re: Set Focus & 2108 error
- References:
- Set Focus & 2108 error
- From: dave h
- Set Focus & 2108 error
- Prev by Date: Re: Extracting Fractions
- Next by Date: Re: append contents of field to another field
- Previous by thread: Set Focus & 2108 error
- Next by thread: Re: Set Focus & 2108 error
- Index(es):
Relevant Pages
|