473,511 Members | 16,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to change the control source of fields by selecting a value in combo box?

6 New Member
Hi,

I have a Form with record source set to a Table1 and all the fields' control source in the Form are set to the fields in the Table1. And by clicking "add" button, the entered data in the Form gets saved as a record in Table1. Now what I'm searching for is, when I click a value in a combo box in the Form, all the fields' entered data should get saved in Table2 on clicking the "add" button.
I'm a novice in coding. I appreciate any help.
Nov 10 '14 #1
14 1244
Seth Schrock
2,965 Recognized Expert Specialist
So you want the same data entered in table2 as you are saving in table1? This seems like a very poor design, as you should almost (like only 0.0000001% of the time) never had duplicated data in a relational database (such as Access). What are you trying to do? We may be able to help you come up with a better solution.
Nov 10 '14 #2
chaitu19
6 New Member
No, We don't want the data to be saved in Table1 when we click a unique value in combo box. The data should only get saved in Table2.
Nov 10 '14 #3
Seth Schrock
2,965 Recognized Expert Specialist
So in other words, you want the record source of the form to change to table2 if you select the appropriate value in the combo box?
Nov 10 '14 #4
chaitu19
6 New Member
Actually I did that, by selecting the appropriate value in the combo box, the record source of the form changes to Table2. But the data entered in the fields are not getting saved into the Table2, when I click the "add" button.
Nov 11 '14 #5
jforbes
1,107 Recognized Expert Top Contributor
I'm curious to see how you are doing this. Are you using Bound Controls, bound to Table1, or are you using Unbound Controls and then creating the SQL Insert command and executing it when the user clicks the Add Button?

For this scenario it would probably be easiest to Execute the SQL OnClick.
Nov 11 '14 #6
Seth Schrock
2,965 Recognized Expert Specialist
We would need to see the code behind the Add button. Please use code tags (the [CODE/] button) when posting.
Nov 11 '14 #7
chaitu19
6 New Member
#jforbes, I'm using Bound Controls, bound to Table1 when the user clicks "add" button.

#SethSchrock, this is the code behind "add" button on click()
Expand|Select|Wrap|Line Numbers
  1. DoCmd.RunCommand acCmdRecordsGoToNew
Nov 11 '14 #8
zmbd
5,501 Recognized Expert Moderator Expert
If the fields in Table2 have the same name as in Table1, then by setting the [record source] for the form to the correct table should be the ticket. Otherwise, it sounds as if you have hardcoded the [control source] for each control to the first table.

As stated, we'll need to see your code.
Please follow the guidelines found in the following link before posting: [*] > Before Posting (VBA or SQL) Code
Nov 11 '14 #9
Seth Schrock
2,965 Recognized Expert Specialist
I'm having trouble getting around the idea of why the two tables still. I'm thinking that it would be a lot easier if you added a Category field to Table1 to separate the records instead of tables. You can create queries that act as virtual tables to split the data out. You should look at Database Normalization and Table Structures.

What is the code that you are using to change the record source of the form?
Nov 11 '14 #10
zmbd
5,501 Recognized Expert Moderator Expert
Seth,
I'm thinking OP is on the mindset of late-bound tabbed control type concept. Using one form for multiple tables.

Still, as you said, more than likely a better way to do this if OP will explain the idea behind the project.
Nov 11 '14 #11
chaitu19
6 New Member
Table2 does not contain all the exact fields in Table1. It's like, when we select a specific value in combobx, some of the fields in Form gets disabled and remaining Fields' data gets saved in Table1 and until now we entered saved the data in Table1, but now, when we change the specific value in combobox to save in Table2, we are encountering this problem.

This is the code I used and it's not allowing me to enter the data saying "Control can't be edited, it's bound to unknown field "field name""
Expand|Select|Wrap|Line Numbers
  1. Private Sub cbo_AfterUpdate()
  2. Dim strOption As String
  3. strOption = Me.cbo
  4. Select Case strOption
  5. Case "Community Development":
  6. Form1.RecordSource = table2
  7. End Select
  8. End Sub
  9.  
And this is the code I'm using for "add" button
Expand|Select|Wrap|Line Numbers
  1. Private Sub add_click()
  2. DoCmd.RunCommand acCmdRecordsGoToNew
  3. End Sub
  4.  
Nov 12 '14 #12
Seth Schrock
2,965 Recognized Expert Specialist
You would need to enclose your recordsource in double quotes.
Expand|Select|Wrap|Line Numbers
  1. Me.RecordSource = "table2"
Nov 12 '14 #13
chaitu19
6 New Member
It works perfect.
Thanks to all of you.
Nov 12 '14 #14
Seth Schrock
2,965 Recognized Expert Specialist
Glad we could help. Good luck on your project.
Nov 12 '14 #15

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

Similar topics

9
7393
by: Jack | last post by:
In the control source of a textbox, is there a way to refer to a column of a combobox? For example: =.Column(2) Thanks, Jack
3
2816
by: klawiter | last post by:
Greetings, I have a table with two columns. On my form, I have a combo field that displays the contents of the first column. Upon selecting an item in this combo field, I would like to then...
2
4895
by: jerry.ranch | last post by:
I've been using row source with the QBE for my list and combo boxes..when would I use control source? jerry
1
1653
by: andy | last post by:
I have three things, 1. a form with a combo box on it. 2. A lookup table with 2 fields, RMName and RMmrm. 3. A table with site information including an RM field and an MRM field. The combo box...
3
1773
by: wideasleep | last post by:
I have a subform that's a continuous form. In it I have a combo box that fills a date field. It works great except for one thing. It fills in all the other date fields for each record and the combo...
3
14412
by: papata123 | last post by:
I would like to use a set of three option buttons on a form so that depending on which one is selected a text box is bound to one of three corresponding fields. I'm not really sure what the code is...
3
1434
by: annd1968 | last post by:
Hi! Can a control source for a report be dynamic and programmed based on a form selection? I have a form where a user selects one of 5 cities in a combo box. This should then display a report...
5
4510
by: bessora | last post by:
I have a form and combo boxes on it. Depending on what is current record of a form, I need to dynamically (in the code) change the row source of at least one combo box. Problem is that when I read...
16
6959
by: Xenver | last post by:
Hi All, I have many buttons on a form, i want each of these buttons to open the same form but change the control source of the textbox on the form so i can use it to update multiple fields and not...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7418
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3222
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
446
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.