Command Button

kitty77

Registered User.
Local time
Yesterday, 20:06
Joined
May 27, 2019
Messages
719
What is the vba code for: afterupdate, goto a command button and click it?
 
Just call the click event. For example:

ButtonName_Click
 
When I click the button manually, it works. It opens another form. When I use Command5_Click I get an error.
 
1645560384629.png
 
When I click the button manually, it works. It opens another form. When I use Command5_Click I get an error.
Can you show us the code in the Click event of the button please? Thanks.
 
Since there is no parameter inherent in a Click event try this:

Call Command5_Click

Then put a breakpoint on that line of code. When it breaks, single-step (using Step-Into, which you can find on the VBA code-page menu). One line at a time see what it does.
 
Here is what's in the command button.
View attachment 98482
Ah, that's an embedded macro. Not sure you can execute it another way aside from clicking on the button. If you must use macros, you might use a named macro instead. Otherwise, you could repeat/duplicate the macro in your other code. Just a thought...
 
Given that the OP posted the code behind the button in question, does anybody still think it belongs in a Standard Module? Just curious...
 
Ha! Its a macro!

It should immediately be converted into VBA and the perpetrator of the offence should be banned from (AWF) Access World Forums!
But I was referring to its content (the code inside the macro). Even if you convert it into VBA, do you really think it should be in a Standard Module. I was just curious...
 
I totally agree that code repeated more than once should be transferred to a separate procedure, either within the form module or, where appropriate, in a standard module. I do that all the time for exactly the reasons Tony described.

However, in this case where the button click code is simple and used in just one other place, I see no reason to create a separate procedure just for the sake of it. However, I would definitely replace that embedded macro with VBA
 
Yes, as I said....
Well, it is almost a year on but reading it again it seems to me my comments and yours weren't the same

We both agree that multiple uses of the same code should go in a module.
But to repeat my earlier comment:
However, in this case where the button click code is simple and used in just one other place, I see no reason to create a separate procedure just for the sake of it.
That's still my opinion
 
We'll have to agree to disagree in that case.
I often call a button click event from one other event in the same form.
 
I often call a button click event from one other event in the same form.
If the button doesn't wobble properly and visibly, it's incomplete.
No, an event procedure without the event is debatable.
 
If one speaks of good programming: Here one has thought about it.
 

Users who are viewing this thread

Back
Top Bottom