Link to home
Start Free TrialLog in
Avatar of darls15
darls15

asked on

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
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

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
Avatar of darls15
darls15

ASKER

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
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
Avatar of darls15

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think all you need is the "reverse" action:

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

/gustav
Avatar of darls15

ASKER

Hi Ron

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

darls15
You're welcome.

Ron