[RESOLVED] Shortcut key to a form's button while a MdiForm is existed
Hi~ I am very fresh in VB, this forum really help me a lot.
Actaully what I want to do is assign a shortcut key to a button (Alt+a) at form A. But, the problem is, system take priority of run MdiForm's menu first once i press "Alt" key on the keyboard.
So, I think for another way to overcome this problem that is call the Command1_Click function by MdiForm's menu.
The code I write is for the mdiForm menu is:
vb Code:
Private Sub menuAdd_Click()
Call formA.Command1_Click
End Sub
Sure, it doesn't run bcoz the data member .Command1_Click is not found.
Anyone have an idea?
Re: Shortcut key to a form's button while a MdiForm is existed
You can directly call like this
vb Code:
Private Sub menuAdd_Click()
btnAdd_Click
End Sub
Re: Shortcut key to a form's button while a MdiForm is existed
Thanks for your fast respond~ :)
It doesn't work. bcoz the btnAdd_Click function is in Form A, but menuAdd_Click function is in MidForm, is 2 different form~ :ehh:
Re: Shortcut key to a form's button while a MdiForm is existed
You could do onething.Place a Function in a Module.And in the click event call that Function
Re: Shortcut key to a form's button while a MdiForm is existed
hmm~ i think of this way before, but is it suitable to create a new module just for a single form's local function?
really appreciate your idea~ i will giv a try~ thX
Anyway, now what i most want to know is How to assign a ShortCut to a form's button if a mdiForm is existed? It is the straightest way to solve my problem~ :)
Re: Shortcut key to a form's button while a MdiForm is existed
You can do this like this
1.Trap the key press event
2.In that Suppress that event.and call your click event
Re: Shortcut key to a form's button while a MdiForm is existed
Quote:
Originally Posted by Ropyon
Hi~ I am very fresh in VB, this forum really help me a lot.
Actaully what I want to do is assign a shortcut key to a button (Alt+a) at form A. But, the problem is, system take priority of run MdiForm's menu first once i press "Alt" key on the keyboard.
Put this code in Form A
Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbAltMask And KeyCode = vbKeyA Then
'do what you want here
End If
End Sub
Re: Shortcut key to a form's button while a MdiForm is existed
If you want to execute what is in the click event of a button on another from do
Code:
Form1.Command1.Value = True
Re: Shortcut key to a form's button while a MdiForm is existed
Or just Form1.Command1_Click
Re: Shortcut key to a form's button while a MdiForm is existed
Quote:
Originally Posted by Hack
If you want to execute what is in the click event of a button on another from do
vb Code:
Form1.Command1.Value = True
LoL, what a simple code? But it was answered my question about execute another form's function from mdiForm!! thx Mod!!~
Re: Shortcut key to a form's button while a MdiForm is existed
Quote:
Originally Posted by Al42
Put this code in Form A
vb Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbAltMask And KeyCode = vbKeyA Then
'do what you want here
End If
End Sub
Yeah, this is actually what i want find out! Assign a ShortCut key to a Function.
Once i press the "Alt + A" button, the function was executed! But I should replace the Form_KeyDown to Command1_KeyDown first.
Thx alL of you efffort to help me~ appreciated and hope it wilL help other so. :wave: