Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Buttons & variables (97/SR2)

    Quick question:

    Is there a way of assigning a button name to a variable and the use it i.e. me.VariableName.enabled = true?
    Basically, I have a module that will run on every button on the form. I can copy the module to every button, but I'd like to have it as a stand alone module which the uses a global variable in the me.button.enabled code.
    Not sure if this is possible as I have been unable to get it to work - I may be using the wrong variable type. I tried string to start with, then I tried defining buttonID as .button (never used it, not sure what it does, but I thought I'd give it a go!).
    Any help would be much appreciated.

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Buttons & variables (97/SR2)

    You can do it, but that isn't the syntax. Try

    Me(VariableName).Enabled = True

    But why would you use a global variable? It's better (and more reuable) programming to pass the value into the routine as an argument.

    I'm not sure what you're trying to do by defining buttonID as .button <img src=/S/confused.gif border=0 alt=confused width=15 height=20>. If you want to define an object variable for the button, it would be dimmed as a CommandButton.
    Charlotte

  3. #3
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Buttons & variables (97/SR2)

    Thanks for the help Charlotte.
    The reason I didn't think of passing the value as an argument was simply that i'm not very familiar with external modules. Most of my programming to date has been in modules such as the on click event, and not stand alone modules. I will give it a go just as soon as I've worked out the other problem, which you have also kindly provided an answer for.

    The reason I want to define the button is this:
    I have a database with a set of menus that open various forms. Depending on the user and what privalages they have determines what forms are available. As they click on each button, the module will run and return whether permission is denied or not. I also have a similar function to write that will run as the database starts and perform the task on a whole set of menus in one go (some kind of For Next loop).

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Buttons & variables (97/SR2)

    I generally pass objects to external routines, such as passing a Me reference to a routine that accepts a form object variable or a Me.cmdButton to one that accepts a control object variable when I don't want to have to loop through a bunch of objects. The object variable gives you lots of flexibility and provides access to the methods and properties of that object. Of course, if you only want to handle a particular *kind* of control, then you can pass either a string that holds the name of the control or a values that represents the type of control it is instead.
    Charlotte

  5. #5
    Lounger
    Join Date
    Apr 2001
    Location
    KY USA
    Posts
    45
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Buttons & variables (97/SR2)

    Quick Example:

    public sub Math(Value1)
    dim Problem as int

    select case Value1
    case is = "-"
    Problem = 5 - 5
    case is = "+"
    Problem 5 + 5
    end select
    msg box "Problem"
    end sub.

    Then you set two buttons, one says On Click Math "+", and one says Math "-"

    When you click the buttons, depending on which one you click it will give you a message box with either 0 or 10.

    jeff

  6. #6
    4 Star Lounger
    Join Date
    Feb 2001
    Location
    Gillingham, Kent, England
    Posts
    511
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Buttons & variables (97/SR2)

    Thanks for the tips and examples with modules, I don't think it'll take me too long to get into the habbit of using them. I can remember using them in Pascal & C at college a few years back and they're not much different from that.

Posting Permissions

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