Combo Box Selection from a link on different form (1 Viewer)

T. McConnell

Registered User.
Local time
Today, 11:59
Joined
Jun 21, 2019
Messages
63
Greetings all,
Been a while since I have needed some help, sadly that time has come again haha. So here is my issue this time.
I have a form that I have created a link from one of the fields called Product, I have another form that has a combo box on it called cboProduct.
What I would like to do is when I click on the link (Product) on my initial form, I want it to open the form called frmStockMovements and autofill the combobox with the "Product" name already selected.
I have tried the using the DoCmd form to open the form and pass the value to the combo box, but can't seem to get the value to pass to the combo box.
What basically happens now is when I load the frmStockMovements form I select the product from the drop down and it populates that form with that product information. I want this to happen naturally when clicking on the link from the initial form.
Any help would be greatly appreciated.
Thanks :)
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:59
Joined
May 21, 2018
Messages
8,463
Pass by openargs if you open the form ACDIALOG
If not simply set the value from the calling form after you open the form.
Forms("theOpenedFormName").somecombo.value = somevalue
 

T. McConnell

Registered User.
Local time
Today, 11:59
Joined
Jun 21, 2019
Messages
63
Thanks MajP,
I ran into another issue now, I get the value passed however the function that happens on this combo box is when a selection is made (on the change event) would open a subform with the action to add more quantity into stock as well as displaying two other controls when a selection is made. What happens when I use this code is it does pass the value over to the combo box, however the only way I can get the other information to display is by selecting an option from the combo box which kind of defeats the purpose. Is there a way to force a "fake" onchange event so to speak when this code is ran to trigger the other items to display.
I would post a copy of the database, but there is sensitive data, I will try and provide what I can.

Edit: I should also mention that the link to click to open this is on a subform on the main form.
Main form name is frmOpen, the subform name is frmPartsToOrder. When clicking on the link to open the Part order form (frmStockMovements) it should automatically display the name in the combobox and display all other controls on the form.

Thanks again for your help.
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 11:59
Joined
May 21, 2018
Messages
8,463
You can call that event procedure. But the cleaner way to do that is to move all the code out of the on change event and paste it into a new Procedure. So Instead of
Code:
Private Sub SomeControl_Change()
  'lots of code here
end sub

Change it to
Code:
Private Sub SomeControl_Change()
  newSubName  
end sub

Public Sub NewSubName
  'Put the code here ensure it is public
end sub

Now from the calling form
Code:
docmd.openform "SomeFormName"
Forms("SomeFormName").somecombo.value = somevalue
Forms("SomeFormName").NewSubName   'call the sub from the form that opened it
 

T. McConnell

Registered User.
Local time
Today, 11:59
Joined
Jun 21, 2019
Messages
63
Crazy question, is there a way to force an after update selection on a combo box without actually making a selection? Reason I ask this is when my form opens up after the value is passed to the combo box, the only way I can get the other fields to display (currently not visible until a selection is made) is by reselecting the option from the combo box. I am trying to avoid this extra step and have the the form reflect the change technically without actually making the selection... If any of this makes sense, sorry it is late here lol.
Thanks again
 

Users who are viewing this thread

Top Bottom