Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Non Absolute references problem with items selected in a listbox 1

Status
Not open for further replies.

MikeAuz1979

Programmer
Aug 28, 2006
80
AU
Hi,

Using access 2000 I have 2 list boxes that are supposed to perform the same action so I moved the code out to a module so I didn't have to repeat code, but I'm having trouble with that.

Below is my code which works fine when the listbox name is hardcoded into the for each line but I get an application deifned error when I try and run this using the line
Code:
Call OpenAppoint(Me.lstDay)

Anyone have any ideas?

Thanks for any help
Mike
Code:
Public Sub OpenAppoint(Ctrl As Control)
dim frm as form

Set frm = Forms!frmSearch
For Each varItm In frm.Ctrl.ItemsSelected
       Surname = frm!Ctrl.Column(1, (varItm))
       Breed = frm!Ctrl.Column(2, (varItm))
       DogName = frm!Ctrl.Column(3, (varItm))
Next varItm
 
How about:

Call OpenAppoint(Me,"lstDay")

Code:
Public Sub OpenAppoint(frm, CtlName)
For Each varItm In frm(CtlName).ItemsSelected
       Surname = frm(CtlName).Column(1, (varItm))
       Breed = frm(CtlName).Column(2, (varItm))
       DogName = frm(CtlName).Column(3, (varItm))
Next varItm

You may wish to consider ActiveForm and ActiveControl.
 
But your question may still be why cant you pass the control because this looks correct? I am not totally sure why this happens (maybe someone can answer), but I know how to fix it and what it is doing. If I need to pass the control the procedure that I am passing the control to must reside in an external module, not in the form's module. If you leave the procedure in the form's module
me.yourcontrol
gets coerced into the controls value not the control object even if the parameter is a control object.


I think that this also may fix it, but not sure.
dim ctrl as access.control
set ctrl = me.lstDay
callOpenAppoint(Ctrl)
 
Remou, works perfectly and saved me hours of staring at a screen, love your work.

Mike
 
MikeAuz1979 . . .

Agree with [blue]MajP[/blue]. If you indeed did move the code to a module in the modules window, I have:
Code:
[blue]Public Sub OpenAppoint(LBx As ListBox)
   Dim frm As Form, idx
   
   Set frm = Forms!frmSearch
   
   For Each idx In LBx.ItemsSelected
      frm!Surname = LBx.Column(1, idx)
      frm!Breed = LBx.Column(2, idx)
      frm!DogName = LBx.Column(3, idx)
   Next
   
   Set frm = Nothing

End Sub[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top