Re: Set Focus & 2108 error

Tech-Archive recommends: Speed Up your PC by fixing your registry



"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)


.



Relevant Pages

  • Re: Script problem with Windows 7
    ... me to bring IE to the top and set focus to it. ... you don't have a variable to reference the IE ... Sub IE_DocumentComplete ... If you run that code you should get an IE window ...
    (microsoft.public.scripting.vbscript)
  • Set Focus & 2108 error
    ... you must set focus first. ... Private Sub Form_Load ... Private Sub List1_BeforeUpdate ... ' it you put the above code in here you will get a 2108 runtime error ...
    (microsoft.public.access.formscoding)
  • Re: Set Focus & 2108 error
    ... Here is how I was actually using the code to iterate thru the entire list ... lets say for some reason ... you must set focus first. ... >> Private Sub Form_Load ...
    (microsoft.public.access.formscoding)
  • RE: Next record on parent form after update of child form
    ... RTE 438 - Object doesn't support this property or method. ... I've tried to set focus and move control to the main form from the ... >> Are there special considerations when moving back from sub to main. ...
    (microsoft.public.access.modulesdaovba)
  • Set focus to control in another subform on the same form
    ... This is all in a subform, ... when the user tabs out of the phone #, the cursor goes back to the Area Code ... Private Sub txt_Phone_Number_KeyDown ... set focus the the Area Code field in the next ...
    (microsoft.public.access.formscoding)