FormRef.ProcedureName Arg1, Arg2, ...
or
CallByName FormRef, "ProcedureName", VbMethod, Arg1, Arg2, ...
ApplicationReference.Run "ProcedureName", Arg1, Arg2, ...
Public Sub YourButton_Click()
Msgbox "I was pressed"
end Sub
private Sub YourButton_Click()
ShowClickMessage
end Sub
Public Sub ShowClickMessage()
Msgbox "I was pressed"
end Sub
ReferenceToForm.ShowClickMessage
Private Const WM_KEYDOWN As Long = &H100
Private Const WM_KEYUP As Long = &H101
Private Const VK_RETURN As Long = &HD
Private Const VK_SPACE As Long = &H20
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Sub Test()
DoCmd.OpenForm "TestForm"
PressButton Forms("TestForm"), "cmdTest"
End Sub
Public Sub PressButton(ByVal frm As Form, ByVal ButtonName As String)
'1. set focus to commandbutton
frm.Controls(ButtonName).SetFocus
'2. press return or space key:
SendMessage frm.Hwnd, WM_KEYDOWN, VK_SPACE, 0
SendMessage frm.Hwnd, WM_KEYUP, VK_SPACE, 65539
End Sub
This is a pretty scary process. Perhaps there is a better solution. Tell us in words why the process is in a different database. There are ways to create add-ins so you can reuse code rather than duplicating it. Maybe this would be a safer approach.Is it possible to call the code written behind the MS access Form button of another access file?
If Yes, please share the code snippet how to call it?
Thanks in advance!!
Right, lost my mind. It's such a small thing. So easy to misplace.Pat, the answer to your question is in the OP's title... Automate MS Access Testing.
Right, lost my mind. It's such a small thing. So easy to misplace.