• Buttons & variables (97/SR2)

    Author
    Topic
    #363662

    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.

    Viewing 1 reply thread
    Author
    Replies
    • #555671

      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 confused. If you want to define an object variable for the button, it would be dimmed as a CommandButton.

      • #555686

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

        • #555761

          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.

    • #555777

      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

      • #555856

        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.

    Viewing 1 reply thread
    Reply To: Buttons & variables (97/SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: