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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK

Micron

Well-known Member
Joined
Jun 3, 2015
Messages
2,233
Office Version
  1. 365
Platform
  1. Windows
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?
 

welshgasman

Well-known Member
Joined
May 25, 2013
Messages
901
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?
 

JonXL

Active Member
Joined
Feb 5, 2018
Messages
482
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
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.
 

Forum statistics

Threads
1,141,072
Messages
5,704,129
Members
421,328
Latest member
CBL

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
Top