Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2004
    Posts
    38

    Unanswered: Passing a controller as a vriable

    How can I pass a reference to controller as a variable to a method? I mean - I wanna write a general method to update some stuff on a combo box controller - and I dont wanna rewrite it for every form, so I wanna pass a reference to the correct controller to this method

    Thanx ahead, dd+

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    What do you mean controller?

    Do you mean reusing the same code in the event handler for a bunch of different controls?

    If so, create a new module with a sub that will accept a form and controlname as arguments. Then call you're new sub from your control's event handler.

  3. #3
    Join Date
    Mar 2004
    Posts
    38
    Thats exactly my question - how can I pass a form and controller name as argumaents and use them later?

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    see this for how to pass a control (in this example a textbox) around an application (in this example, to a report).

    izy
    currently using SS 2008R2

  5. #5
    Join Date
    Mar 2004
    Posts
    38
    Docmd.OpenForm takes a string var as an argument so ofcourse you can set a global string var with the referenced controller.
    But I need to set a specific controller inside a form (an activex controller to be exact):
    Forms![PictureTest]![Picture1].Picture = pic

    I wanna pass the "Forms![PictureTest]![Picture1]" as an argument to this method, in case I have the same activex controller on a different form (i.e. Forms![PictureTestNumber2]![Picture1]" or "Forms![PictureTest]![Picture13]" )

    Did I manage to explain myself?

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    a couple of things:

    i was not setting a global string - look again: it's a global object

    you didn't mention a picture box before... i've never tried it but a picture box is an object just like any other so just dim it and run. far as i'm aware there is no specific picturebox object i.e.
    global mybox as picturebox
    doesn't look a likely solution.

    try:
    global mybox as object
    global mybox as control
    or something like that. like i said, i didn't try it with a picture box, but the object must exist and so you can pass it round the application as an object.

    izy

    LATER: i see there is an "image" object so try
    global mybox as image


    EVEN LATER: you don't always need a global, depends on what you are trying to achieve. see this for an example of using a private object and passing it to a destination form through a setup routine in the destination form. note that this sort of game only works when you play with the object rather than the object's name
    Last edited by izyrider; 04-18-04 at 11:40.
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •