How to capture the value of a combo box on unbound form

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

How to capture the value of a combo box on unbound form

Post by BittenApple »

Hello team,
I want to capture the value of a combo box which lays on an unbound form and show it in a text box on a subform. Main form where combo box sits on and sub from are linked through Master and Child link.

I inserted a textbox on the subform and In the property window:

I named the text box and added this to control source of the text box
MainformName.thenameofcomboBox.[Column](1)

When I run the form: the text box shows #Name.
I entered just the name of the combo box in the text box,
When I run the form: it only shows the hospital_ID only by 20 and for hospital ID 21, the text box goes blank
I thought it is good idea to enter some code in the after update event of the main form or subform, my application didn't work at all and it got messed up and I had to came back to pervious version.
I entered this code in after update event of the main form:
Me!myTextName.Text=Me.MycomboBox.column(1)

No success yet!
I appreciate any tips.

Regards,
BittenApple

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to capture the value of a combo box on unbound form

Post by HansV »

What happens if you set the Control Source of the text box to

=MainformName!thenameofcomboBox.[Column](1)
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hello Hans,
for one of the values of combo box show: # Name and for the rest, it is blank, as far as I tested it.
Regards,
BittenApple

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to capture the value of a combo box on unbound form

Post by HansV »

And if you use

=Parent!thenameofcomboBox.[Column](1)
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Ommmmgggg. it is working. Thank so very much for it.
As far as, I tested it, it works!!!!
The reason, I inserted the text box on the sub form was to capture the changes on the combo box. Combo Box was on the unbound form, you told me the changes on the unbound from is unrelated. Really, I changed the Audit code that I received in this form a while ago, still, The code was showing which hospital was changing but it didn't show to which record belong to. As you said, it was unrelated.

I inserted this text box and tagged it Audit to be able to trace the changes on the combo box whose values is now captured in the text box. As soon as, I put Audit in property window on text box, the Microsoft Access shuts down and offers me to debug the program in Visual Studio. So, I am going to only capture the value for now.

Thanks for all you!!!


Regards,
BittenApple

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hello Hans,
Thank you so very much for the response.
I was able to pull the value of combo box and showed it on a subform in a text box.
I tagged and untagged the text box, (I tagged it to use the control in a code), either way, it gives me an error.
Access shuts down and it reopens with a message to debug and a back up created automatically.

I thought, I can insert the text box and just to show the value of Hospital ID from the table that is source for subform, that didn't work either. The Hospital ID stays blank in the source table for subform, which previously it was created automatically (Form, subform linked together).

This task is only for enhancing the application, although It is nice to find a solution for it.

Regards,
BittenApple

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to capture the value of a combo box on unbound form

Post by HansV »

Isn't the hospital ID the field that links the main form and subform? If so, it will be filled automatically.
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hans,
Yes, Hopital ID is the field that links main form to subform and it is filled automatically; agreed.
Once, I linked form and subform, I deleted Hospital ID field from the sub form; now I need it back, because I want to tag it to make my code save the changes to it.
When I add it back to subform, it has to show the hospital ID which is filled automatically; it doesn't display any thing at all and it is blank. I have experienced it before as well, when we delete a field from the form or subform, when we want it be back, it creates problem, that has been my experience.

When I use:
=Parent!thenameofcomboBox.[Column](1)
Access shuts down and then again restarts after a while by itself.

Regards,
BittenApple

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to capture the value of a combo box on unbound form

Post by HansV »

Without seeing the database, it's impossible to tell what's causing the problem.
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hans.
I don't know why and I can't find any explanation for it, but this worked for me.
Many thanks,
BittenApple

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hello,
I have a database and I made a query to feed a report, that is how I captured the value of a combo box on the form in the query:
[Forms]![MainForm]![txtTitle]
It works perfect. I am doing the same steps for another query for another report in a different database. (I have been working on it for all day and no success)
Mainform has got a combo box which its value comes from a query; combo box works well and I am able to capture its value in a textbox on the header of the form, now I want to use the value of the textbox or combo box in a criteria of the query, no success, what the problem is?

How should I pass the value of the combo box to the query? The difference is on the first database, the combo box is based on the table, on the second database, the combo box is based on a query.

Any help is greatly appreciated!!!

BittenApple

User avatar
HansV
Administrator
Posts: 78620
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: How to capture the value of a combo box on unbound form

Post by HansV »

The first column is usually the bound column of a combo box, so you should set the criteria on the field that corresponds to the first field in the query.
But if you have set the Bound Column property of the combo box to 2 (or 3 or ...), you should set the criteria on the field that corresponds to the 2nd (or 3rd or ...) field in the query.
Best wishes,
Hans

BittenApple
BronzeLounger
Posts: 1498
Joined: 01 Mar 2015, 02:03

Re: How to capture the value of a combo box on unbound form

Post by BittenApple »

Hans,
So many thanks for the response. I eventually discovered what the problems is after working 20 hours on it.
I tested on what you are suggesting as well. The problem was coming that the data source for the Main form was a table, the source for the Combo Box data was a query on that table. That was creating problem. I tested several time, it is fixed. I couldn't save my work though I have to test it tomorrow again.
Thanks for all!!!