By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,863 Members | 879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,863 IT Pros & Developers. It's quick & easy.

Is it Possible to Change ControlSource of a TextBox based on ComboBox Selection?

P: 3
Hi guys.
I'm wondering if it's possible to do this in MS Access.
I'm capturing the login and logout time of employees in my company. I'm currently using 5 forms of Monday through Friday to populate the employeesTable, across multiple files of 1st week, 2nd week, and so on. The table has the name of each employee and his/her login and logout fields from Monday to Friday on a single row, making 10 fields per row. Is it possible to create one single form that can populate this fields everyday? Example, I will like to create one combobox that has name of the working days of the week, and two textBoxes of login and logout that will populate the login and logout fields on my employees table. When when I select Monday from my combobox, the Control Source of the textboxes will refer to Monday fields of the employees table, and when I select another day like Friday, it will refer to Friday fields.


Thanks
Jun 7 '17 #1

✓ answered by NeoPa

Misbahu:
The original question was to create a single form with textbox that can refer to multiple fields base on combo box selection, so that I can enter all login and out time with single form.
Although I've given a direct answer to that very question (See the Post #5), I would advise that you put your attention to the other advice given rather than to use it.

Share this Question
Share on Google+
7 Replies


jforbes
Expert 100+
P: 1,107
You can do this, but you'll be much better off if you Normalize your Data instead of having separate fields for Monday through Friday. I know this is not what you asked for, and you can do what your asking, but with every thing going forward that you attempt will be complicated if you don't have your database normalized first.

This is a link that explains Normalization: Database Normalization and Table Structures
Jun 7 '17 #2

P: 3
Thank you for your response and the data normalisation link. It really help. Another question, how do I really do that? I mean the combo and text box thing.

Thanks
Jun 7 '17 #3

PhilOfWalton
Expert 100+
P: 1,430
JForbes is spot on about normalisation.

My beginners guide is very simple. A table should consist by and large of things that apply to a single subject. In your case, a table of employees would consist of names, emails. mobile phone, gender, colour of eyes etc. Absolutely nothing to do with whether they have come in to work. People will argue on this, but I don't personally ever include the address with the person, as the address exists in it's own right and often a number of people live at that address. Within the Employee table there would be a pointer (called a foreign Key FK)) that points to their address.

Equally, although you are talking about Monday to Friday, they are just dates and we can find out that 7th May 2017 is a Wednesday. Again those dates exist; whether anyone works on them is irrelevant.

Then you need a table to link the Employees to those dates with a Login & Logout time.

When you feel that you have a table structure that is normalised, send an image of the relationships pane, and I feel sure you will get more help if you need it.

Phil
Jun 7 '17 #4

NeoPa
Expert Mod 15k+
P: 31,418
Misbahu:
Another question, how do I really do that? I mean the combo and text box thing.
Essentially the original question.

Let me start by endorsing the comments by both JForbes and PhilOfWalton. Very wise advice.

Nevertheless, your question is about how to change the ControlSource of a TextBox control depending on the selection of a ComboBox. That's actually blindingly straightforward. Assuming the the ComboBox is called cboDay, the TextBox is called txtIn and that cboDay returns a value that is the name of the field you want the TextBox to use, then the code is simply :
Expand|Select|Wrap|Line Numbers
  1. Me.TextBox.ControlSource = Me.ComboBox
Jun 7 '17 #5

P: 3
Thank you guys for your help. I really appreciate it.
However, I was confused on the normalization process. The data entry of the login and logout time is done every day. Every day new login and logout time is captured for each and every employee, adding up two fields for every employee every day. I thought of creating separate tables of the days (Monday - Friday) with the login and logout time and relate these tables to the employees table. But how does these tables add up the subsequent login and out time for the up coming weeks and months. Or do I have to create more tables to hold the log time for each and every day of the week and months? Which is what I was trying to avoid. I don't want to create many unnecessary tables and forms that does basically the same thing.

The normalization is a good idea, I just can't figure out how to normalize the database to perfectly accommodate what I am trying to accomplish.

The original question was to create a single form with textbox that can refer to multiple fields base on combo box selection, so that I can enter all login and out time with single form.

sorry for my bad English.
Hope you guys will understand what I mean.
Thanks
Jun 8 '17 #6

PhilOfWalton
Expert 100+
P: 1,430
Your English is fine.

A normalised database will do just what you want.

Basically you will have a main form based on dates (& hence day) and a continuous subform showing Employee name (picked from a Combo box) and then enter their login & logout times.

Have you had a go at creating the tables that I suggested?

Phil
Jun 8 '17 #7

NeoPa
Expert Mod 15k+
P: 31,418
Misbahu:
The original question was to create a single form with textbox that can refer to multiple fields base on combo box selection, so that I can enter all login and out time with single form.
Although I've given a direct answer to that very question (See the Post #5), I would advise that you put your attention to the other advice given rather than to use it.
Jun 8 '17 #8

Post your reply

Sign in to post your reply or Sign up for a free account.