Sending value and {Enter} to control on second form

G

Guest

If I already have a frmA and frmB open, how do I sent the value of
cmbComboBox on frmA to a txtTextBox on frmB and also have the cmbComboBox on
frmA behave as though the Enter key was pressed after the value is set.

If frmA is not open, the following code works (Provided the combo box is the
first control):

MyValue = Forms!frmB!txtTextBox.Value
DoCmd.OpenForm "frmA", acNormal
SendKeys MyValue & "{ENTER}", True

But if frmA is already open I cannot seem to get the sendkeys command to
send the data from frmB to the cmbComboBox on frmA even if I set the focus.
Here is the code:

MyValue = Forms!frmB!txtTextBox.Value
Forms!frmA!cmbComboBox.SetFocus
SendKeys MyValue & "{ENTER}", True

I am using the SendKeys command because I have code behind the cmbBox that
causes the frmA to search for a specific order number so I can just say
Forms!frmA!cmbComboBox = MyValue.
 
A

Allen Browne

To set the value of the combo on frmA to the text box in the current form:
Forms!frmA!cmbComboBox = Me!txtTextBox.Value

Not sure what the Enter is for. If it is to fire the AfterUpdate event of
the combo, use this:
Call Form_frmA.cmbComboBox_AfterUpdate
Note that you will need to remove the "Private" keyword from this line in
frmA's module:
Private Sub cmbComboBox_AfterUpdate

SendKeys is buggy and best resevered for cases where there is no
alternative.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top