Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Unanswered: How to make a macro press a certain button of a form ?

    Hi,
    I used to work with Oracle, and Access is new for me....
    I have a set of steps to to many times :
    3 Update Queries and pressing Buttons in Forms and I like to have something like a script to perform them on one click. I do not own the VB Password, so i cannot just write a new vb function. But I can see the Properties of the Forms, so I can see the name of the Function called by the Button.

    I tried with a macro:
    OpenQuery 'Update1'
    OpenQuery 'Update2'
    RunCode Forms!Formname1![Button Name]
    RunCode Form_fuhur.FunctionName_Click()

    but I don't get the syntax right. Perhaps there is also a better Action to use.

    Thanks to whoever can help

    Fuhur

  2. #2
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    The RunCode macro command only works if the VBA is on a module, not if it's on a form. In order to run a form procedure from a macro, you have to create a function in a module, and that function has to call the form's procedure.

    Sam

  3. #3
    Join Date
    Jun 2012
    Posts
    3

    Red face

    Thanks very much,
    the Button calls a Function "ButtonName_Click()" which is defined in a Module "Module23"

    Can I run this Function directly from the Macro, or would I need one more function? How would be the syntax / the code for this then ?

    I tried, but I get error....

  4. #4
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    I think you misunderstood. If a button calls a function, the function doesn't need to be in a module; in fact it's only an inconvenience to do so. It should run the event right there on the form.

    Only if you must call a macro directly - such as the Autexec macro, or some other task that can only be done in a macro and not in VBA - and then you want to run some VBA code, does the macro have to call a module, and the code won't run if it's on a form. The function can then call additional VBA code that's on the form.

    Sam
    Last edited by Sam Landy; 06-25-12 at 16:02.

  5. #5
    Join Date
    Jun 2012
    Posts
    3
    Hi Sam,
    I think I did not get your point exactly.....

    Perhaps I can explain better:
    I have an Access DB which someone else set up. There are several Tables, Queries, Forms and Reports. It has some VBA Code attached, but Passwordprotected, so I could only look once to that code.
    The Switchboard and the Forms build an Application, so you can run some Queries or VB Procedures using the Buttons. The So far so good.
    After inserting data, the Application requires at the moment to run manually x Queries and Enter The SwitchBoard and Press Some Buttons on the Forms to get the Data prepares for some Report.

    I want to automate this, but I don't have the Password, so I cannot write any own VB
    Procedure.
    I thought I can do this only with a macro, so I can call at once the queries and simulate pressing the buttons by RunCode. I wanted to set up the macro using the "Wizard" provided by Access. So I think you mean this by 'you must call the macro directly'
    Is there any other possibility, or do you know how I have to write in this MacroRecording Tool so it works ?
    THanks a lot, I do not have much experience with Access, I used to work only with Oracle before...

  6. #6
    Join Date
    May 2004
    Location
    New York State
    Posts
    1,178
    In that case, I have bad news and good news for you. The good news is that you won't be bothered by the password protection any more. The bad news is that you have to start over with a new form and all new objects. The reason is that the various controls on the form no doubt have event procedures in VBA right there on - you guessed it - the password-protected form. You can't change that as long as you use this form. Not with macros, not with modules, not with nuthin'. Ergo, you gotta start from scratch - or find out the password.

    Look at the bright side. Now you have the chance to design it your way.

    Best o' luck to you, my friend,

    Sam

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    assuming the other form is open you should be able to force the button's on click event by using something like

    forms!myformname!mycontrolname.click
    where
    myformname is the name of the form
    mycontrolname is the name of the button

    alternatively examine the form and understand the code that is going on in there and replicate that code elsewhere. or better yet push the code into functions and call the functions from wherever they are required. if the code is needed more than once in that form or report then put the functions that do the work into that form or reports code module. if the code is required to be used in more than one form or report then put the functions into a common code module and declare them public there. the form or report events then call the relevant functions. try to avoid putting code that does something in event hooks in a form or report. instead use thoise event hooks to call function(s) that actually do something.
    I'd rather be riding on the Tiger 800 or the Norton

Tags for this Thread

Posting Permissions

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