Automatic Click OK

kevinh2320

Board Regular
Joined
May 13, 2016
Messages
61
I'm looking for code to automatically click OK or ignore the parameter query dialog box when it comes up. The code below is ran off a form button on a on-click event. Everything works except I'm prompted with the parameter dialog box. The code copies the customers name to the clipboard so I don't have to paste or enter when prompted. I just have to click OK. Looking for code to automate.

Private Sub openCustomerFrm_Click()

Me.custName.SetFocus
DoCmd.RunCommand acCmdCopy
DoCmd.OpenForm "customerHomeFrm"

' Me.custNameSetFocus
' DoCmd.RunCommand acCmdCopy
' DoCmd.OpenForm "salesFrm"
' Me.custName.SetFocus
' DoCmd.RunCommand acCmdPaste

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
There is no way reliable way that I know of to deal with a parameter prompt in code (as in 'click OK'). If your code pastes a value to the clipboard, then at some point pastes it into a prompt, then just pass the value to the opening form OpenArgs property and forget the clipboard stuff. When the form opens, use the value in the OpenArgs property. How I have no idea, because your post doesn't reveal enough. The prompt is coming from the opening form because it's looking for a field value?
 
Upvote 0
I'm looking for code to automatically click OK or ignore the parameter query dialog box when it comes up. The code below is ran off a form button on a on-click event. Everything works except I'm prompted with the parameter dialog box. The code copies the customers name to the clipboard so I don't have to paste or enter when prompted. I just have to click OK. Looking for code to automate.

Private Sub openCustomerFrm_Click()

Me.custName.SetFocus
DoCmd.RunCommand acCmdCopy
DoCmd.OpenForm "customerHomeFrm"

' Me.custNameSetFocus
' DoCmd.RunCommand acCmdCopy
' DoCmd.OpenForm "salesFrm"
' Me.custName.SetFocus
' DoCmd.RunCommand acCmdPaste

End Sub
Why not do what most people do and just pass the custname to the opening form?
 
Upvote 0
I'm looking for code to automatically click OK or ignore the parameter query dialog box when it comes up. The code below is ran off a form button on a on-click event. Everything works except I'm prompted with the parameter dialog box. The code copies the customers name to the clipboard so I don't have to paste or enter when prompted. I just have to click OK. Looking for code to automate.

Without reworking a bunch of your process, the easiest way around this is probably to use DoCmd.SetParameter ...

VBA Code:
Private Sub openCustomerFrm_Click()

    DoCmd.SetParameter "parameterName", Me.custName.Value
    DoCmd.OpenForm "customerHomeFrm"
    
End Sub

You need to update parameterName to the name of the parameter in your query (what shows up in the box asking for the parameter). This method doesn't require any copy-pasting or SendKeys - and, in fact, you really should rarely have need for methods that do. The only time I've ever copied anything to the clipboard is when the purpose of the function is explicitly to copy something to the clipboard to save the users the hassle of highlighting and copying themselves.
 
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top