Automate Open form, automate shortkey, close form, reload.

mwal
Lounger
Posts: 42
Joined: 28 Nov 2013, 13:09

Automate Open form, automate shortkey, close form, reload.

Post by mwal »

Hi,
I need a (event) button on the main form to open a form in ms access, the combination alt R has to be automatically entered and the form needs to close after the data has bean read.

The combination keys "alt r" is needed to read data from the barcode reader.

After reading the data in the new form another subform on the main form needs to reload because the data that is entered needs to show the new data on this subform

I use the code for the On click event but the code for the shortkey and reload (requery?) the subform is needed

Code: Select all

Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Offer"
    DoCmd.OpenForm BarcodeDataForm, , , stLinkCriteria
(shortkey code to read data from scanner "alt r")
 DoCmd.Close acForm, BarcodeDataForm 
I have found custom MySendkeys But don't know how to use it.
Best regards,
Michiel

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automate Open form, automate shortkey, close form, reloa

Post by HansV »

Try

Code: Select all

    SendKeys "%r"
% is the code for Alt in SendKeys (+ is used for the Shift key and ^ for the Ctrl key).

Warning: in Windows 7 and later, SendKeys is not always dependable; you'll have to try it.

Remarks:

1) If BarcodeDataForm is a String variable containing the name of the form, you can use DoCmd.OpenForm and DoCmd.Close the way you do. But if BarcodeDataForm is actually the name of the form, you should use

Code: Select all

    DoCmd.OpenForm "BarcodeDataForm"
    ...
    DoCmd.Close acForm, "BarcodeDataForm"
2) The DoCmd.Close line will be executed immediately, it won't wait. So there may not be enough time for the barcode reader to do its thing.
Best wishes,
Hans

mwal
Lounger
Posts: 42
Joined: 28 Nov 2013, 13:09

Re: Automate Open form, automate shortkey, close form, reloa

Post by mwal »

Dear Hans,

Thanks for your reply and explenation. Is it possible to put a pause before closing the form? I can test what time should be enough. I look forward to test it!

Best regards,
Michiel

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Automate Open form, automate shortkey, close form, reloa

Post by HansV »

You could do the following:
- Remove the line to close BarcodeDataForm.
- Open BarcodeDataForm in design view.
- Set the Timer Interval property of the form to 10000 (this corresponds to 10000 milliseconds = 10 seconds).
- Create an On Timer event procedure for the form:

Code: Select all

Private Sub Form_Timer()
    DoCmd.Close acForm, Me.Name
End Sub
The On Timer event procedure will automatically be run 10 seconds after the form has been opened (in Form view), so the form will be closed.
You can make the Timer Interval property larger if needed, or smaller if possible.
Best wishes,
Hans

mwal
Lounger
Posts: 42
Joined: 28 Nov 2013, 13:09

Re: Automate Open form, automate shortkey, close form, reloa

Post by mwal »

Dear Hans,

Thanks for your help! I will try it This week.

Best regards,
Michiel