HASAN-1993
Member
- Local time
- Today, 02:42
- Joined
- Jan 22, 2021
- Messages
- 89
Except if I made the code .OnAction = unitprice()
It will work but directly when i open the menu
It will work but directly when i open the menu
Hi DocSo from the earlier post I suddenly see a hint that the thing you want to call is a routine declared public in the main form. But that can't work correctly because in the sub-form, again that is a DIFFERENT FORM. The code for the sub-form is a DIFFERENT MODULE. And the problem is that unless you have the routine declaration declared public in a GENERAL module, you can't call it from outside its (class) module,
There has to be. Can you post a demo db, so we can see exactly what you mean?There is no solution to this problem![]()
I have put a Form, if you press it with the right Click, the shortcut menu will appear, I want onAction Call Function Insert On Same FormThere has to be. Can you post a demo db, so we can see exactly what you mean?
Okay, after playing with this for a couple of days and consulting with a CommandBar expert, we have concluded using a Sub or Function in the Form's Class Module does not work. I'm afraid you will have to use a Standard Module for this case. If you're trying to execute specific routines placed in each Form, he suggests you create a function in the Standard Module to call the routine from the Form when the user clicks on the Shortcut Menu.I have put a Form, if you press it with the right Click, the shortcut menu will appear, I want onAction Call Function Insert On Same Form
Your efforts are appreciatedOkay, after playing with this for a couple of days and consulting with a CommandBar expert, we have concluded using a Sub or Function in the Form's Class Module does not work. I'm afraid you will have to use a Standard Module for this case. If you're trying to execute specific routines placed in each Form, he suggests you create a function in the Standard Module to call the routine from the Form when the user clicks on the Shortcut Menu.
Good luck!
Could you maintain a tempVar or global variable that is a pointer to the "current" form instance? Then you can put the code in a standard module and operate on the form instance.However, this will not work for me because I am working with Instance Form so the function must be called from the same form
Well, that does complicate things a bit more. Please let us know if you do find a solution. Cheers!Your efforts are appreciated
However, this will not work for me because I am working with Instance Form so the function must be called from the same form
great ideaCould you maintain a tempVar or global variable that is a pointer to the "current" form instance? Then you can put the code in a standard module and operate on the form instance.
Thank youCode:Public Sub Insert() Dim frm As Form Set frm = Screen.ActiveForm MsgBox "Insert " & frm.Hwnd frm.Detail.BackColor = vbGreen End Sub
I open three forms from form2. Make sure to move them. This sets the current form to green.
HahahaVery neat!
Incidentally, if you change this line to frm.Detail.BackColor = frm.Hwnd instead of vbGreen, each form instance will be a different colour each time you run it
View attachment 90183