Selecting a record in an unbound combo box

Hi Experts

On my main form (frmMain) I have an unbound combo box (cboSelectClient) where a user can select a record and details about that client appear in a subform. On the main form I also have a button which, when clicked, takes the user to the installation form (frmInstallations) and opens at the same client record. The code is...

DoCmd.OpenForm "frmInstallations", , , "[cboSelectClient].Value= '" & [Client] & "'"
DoCmd.Close acForm, "frmMain", acSaveYes

This works very well.

I would now like to put a button on the installations form which will take the user back to the main form and to the same client record.

Despite many attempts, I can't seem to make this work.

Is there someone that can please help me with how I might be able to do this?

Thanks
darls15
darls15Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IrogSintaCommented:
If you always intend to go back to the main form, why not just hide it instead of closing it.  Then when you want to go back, you would just make it visible again.
DoCmd.OpenForm "frmInstallations", , , "[cboSelectClient].Value= '" & [Client] & "'"
Me.Visible = False

Open in new window

When you close your other form, just add Forms!frmMain.Visible = True

Ron
darls15Author Commented:
Hi Ron

Thanks for your fast response. Yes, you are right, I could do that, however, a user can also go to other records while on the installations form and then want to return to the main form to the current record they are on.

For this reason, I still need code that will return them back to the main form and to the record they were just viewing on the installations form.

I hope this makes sense.

Thanks
darls15
IrogSintaCommented:
Then you can just open your main form, set your combo box to your Client, and run the event you use when making a selection in your combo box in order to update your subform.  You would need to set that particular event to Public first.  For instance if you use the combo box's After Update event, change Private to Public and use the following code in your other form:
DoCmd.OpenForm "frmMain"
Forms!frmMain!cboSelectClient = Me.Client
Call Forms!frmMain.cboSelectClient_AfterUpdate

Open in new window

Ron
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

darls15Author Commented:
Hi again

Sorry Ron, but I'm not sure what you mean here. I don't run an event to make a selection in my combo box. I just select from the dropdown.

My apologies, but I'm not understanding what you instructions are telling me to do here.

Thanks
IrogSintaCommented:
Well you mentioned that you click on the combo box and the subform gets updated with the client you selected so I assumed you used the combo box's event handler to update the subform.  If it is just getting updated by a Parent/Child relationship, then just ignore line#3  in the code I posted.

Ron

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gustav BrockCIOCommented:
I think all you need is the "reverse" action:

    DoCmd.OpenForm "frmMain", , , "[Client].Value= '" & [cboSelectClient] & "'"
    DoCmd.Close acForm, "frmInstallations", acSaveYes

/gustav
darls15Author Commented:
Hi Ron

I removed line#3 and the code worked perfectly, thank you for your time and patience :)

darls15
IrogSintaCommented:
You're welcome.

Ron
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.