tags:

views:

55

answers:

2

Hi, I can connect to the access database and run functions etc from c#, I can even get a hold of the button I need to click, but I can't make it think it's been clicked.

 nonManagedDb.DoCmd.OpenForm("frmMaintenance", Access.AcFormView.acNormal, MissingVal, Access.AcFormOpenDataMode.acFormReadOnly, Access.AcWindowMode.acWindowNormal, MissingVal);
            var RunRep = (CommandButton)nonManagedDb.Forms["frmMaintenance"].Controls["btnDailySheetsReport"];

That's as afar as I've gotten with this, I've tried reflection to grab it's event and invoke it but it's classed as a COM object only so that's out.

A: 

Get the hWnd of the CommandButton and send it a BN_CLICK message:

SendMessage( hwndButton, 0x00F5, 0, 0 );

where SendMessage may be declared as:

    [DllImport( "user32", EntryPoint = "SendMessageW", CharSet = CharSet.Unicode, SetLastError = true, ExactSpelling = true )]
    public static extern int SendMessage( IntPtr hWnd, int wMsg, int wParam, int lParam );
danbystrom
*couple of google searches later* How would I find the button's handle in this situation?
Tarks
I think a regular CommandButton has a property called hWnd? It least in VB6 it has. Otherwise: *FindWindow* or *GetWindow*.
danbystrom
Are you sure this is possible, the CommandButton is a Com objects and doesnt have a handle property, plus I can't detect the button using spy++ so I have no idea how to get at it with findWindow/GetWindow
Tarks
Never played with Access, no, but done with with many other apps. Seems it a bit different. Have you tried calling *accDoDefaultAction* on the CommandButton object?
danbystrom
Access handles it's controls a lot differently than other environemtns. An hwnd may not be available at the control level unless it's the control with the focus.
Tony Toews
It's a well-known characteristic of Access controls that they have no hWnd until the get the focus. This is a legacy design from back in the days of Win3.x and earlier, when we were still dealing with those 64K resource stacks that had a habit of filling up and taking Windows down. Giving every control on a form a window handle would have brought down the whole structure (in addition to being incredibly slow on the hardware of the day).
David-W-Fenton
A: 

In Access we can call a procedure in another form using the following syntax:

Call Forms.TransactionTotals.UpdateEmployeeHours

or

Call Forms.OtherTransactionsEntry_VendorInvoices.SetInvoiceID(Me.cboVendorInvoiceID)

Now I doubt you can use similar syntax in .Net but maybe that's enough to figure things out via Interop, etc.

Otherwise if you can run a function then create a one line function in Access whose only job is to call the procedure on a form.

Also a click procedure will be called something like

cmdDeleteTransaction_Click
Tony Toews