Results 1 to 11 of 11
  1. #1
    Join Date
    May 2012
    Posts
    132

    Unanswered: how to run a module?

    I have made a module, named module1 whose function is to make table1 on which a query1 will be built.
    1- What code shall I write in a bottom to run module?
    2- Can I make the whole process by one bottom? I mean can I get the final query by just one click, or do I have to run the module to first have the table in hand and then run the query over the table?
    Thank you
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. In VBA, you do not run a module. You call, or execute (run) a Sub procedure or a Function.

    Code:
    Private Sub CommandExecute_Click()
    ' If the sub procedure accepts parameters.
        MySubMakeTable Parameter1, Parameter2, ... 
    ' Or
        Call MySubMakeTable(Parameter1, Parameter2, ...)
    ' If the sub procedure does not accept any parameter.
        MySubMakeTable    
    ' Or
        Call MySubMakeTable    
    ' If the function accepts parameters.
        Result = MyFunctionMakeTable(Parameter1, Parameter2, ...)  
    ' If the function does not accept any parameters.  
        Result = MyFunctionMakeTable
    End Sub
    2. You can call several procedures from the same Sub CommandExecute_Click, one to create the table then a second to create (or open) the query.
    Have a nice day!

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    think of a module as a code library
    you can't call the module directly but you can call subs or functions (or if the moduel is a class properties and methods)

    you can invice code in that module by using, say a function call:-
    in a query
    in a form or report
    a macro

    so you can invoke such code in a module form an autoexec macro (ie when the app first 'wakes up', or as part of a macro run when a user presses command button and so on.

    In a form the code can run as part of user action or attched to the event hooks present in forms and reports
    I'd rather be riding on the Tiger 800 or the Norton

  4. #4
    Join Date
    May 2012
    Posts
    132
    sinndho,
    I really know very less about this subject.
    1- Shall I copy and paste that code in the button on click properties? What are parameters and function? Shall I substitute them with something? I only have a module that is working fine when I press the play in its window but don’t know how I can play there through the button.
    2- Will the procedures called from the same Sub CommandExecute_Click be run in order they are put in the button properties?
    Thank you



    Quote Originally Posted by Sinndho View Post
    1. In VBA, you do not run a module. You call, or execute (run) a Sub procedure or a Function.

    Code:
    Private Sub CommandExecute_Click()
    ' If the sub procedure accepts parameters.
        MySubMakeTable Parameter1, Parameter2, ... 
    ' Or
        Call MySubMakeTable(Parameter1, Parameter2, ...)
    ' If the sub procedure does not accept any parameter.
        MySubMakeTable    
    ' Or
        Call MySubMakeTable    
    ' If the function accepts parameters.
        Result = MyFunctionMakeTable(Parameter1, Parameter2, ...)  
    ' If the function does not accept any parameters.  
        Result = MyFunctionMakeTable
    End Sub
    2. You can call several procedures from the same Sub CommandExecute_Click, one to create the table then a second to create (or open) the query.
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  5. #5
    Join Date
    May 2012
    Posts
    132
    healdem,
    I could not understand any of the answer. I am sorry, my knowledge is less than basic on modules and VBA.
    Do you mean a query can be ordered to be run from module? Does it make functions in order? I mean firstly makes table1 and then the query? Well, something more precise and direct order could be of more help to me.
    Thank you
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  6. #6
    Join Date
    Sep 2006
    Location
    Surrey, UK
    Posts
    994
    Provided Answers: 2
    Why don't you post the contents of the module? That will give others a better idea of what you have, and how best to use it.
    10% of magic is knowing something that no-one else does. The rest is misdirection.

  7. #7
    Join Date
    May 2012
    Posts
    132
    the macro is too long. shall i provide the whole code here? when i play the module it compiles a table. i would like to have this table by pushing a button in a form. i simple don't know how to define the Button Click event to call the Function / Subroutine in the module. in other words what shall i write in the vba code of the button to play the module and i have the table as a result.
    thank you
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  8. #8
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Just the name of the Sub or Function procedure followed by its arguments, if it accepts any.
    Have a nice day!

  9. #9
    Join Date
    May 2012
    Posts
    132
    thank you all guys for your time, it is now working
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  10. #10
    Join Date
    May 2012
    Posts
    132
    and, one more question,
    now, when i push a button, a module is run that puts data into a table ( table1)
    i also want to make a query to be created on table1. can i also add a code to the same button to make both functions? i mean put the data into the table1 firstly and then run the query.
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
    I asked god to please give me everything to enjoy the life, God said: i gave you the life to enjoy everything.

  11. #11
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Create a procedure (Sub or Function) that wil create the query, then call this procedure (you now know how ) in the Click event handler procedure of the button, immediately after calling the one that creates the table (on a different line, though).
    Have a nice day!

Posting Permissions

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