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.
14 1244
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.
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.
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?
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.
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.
We would need to see the code behind the Add button. Please use code tags (the [CODE/] button) when posting.
#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() - DoCmd.RunCommand acCmdRecordsGoToNew
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
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?
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.
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"" -
Private Sub cbo_AfterUpdate()
-
Dim strOption As String
-
strOption = Me.cbo
-
Select Case strOption
-
Case "Community Development":
-
Form1.RecordSource = table2
-
End Select
-
End Sub
-
And this is the code I'm using for "add" button -
Private Sub add_click()
-
DoCmd.RunCommand acCmdRecordsGoToNew
-
End Sub
-
You would need to enclose your recordsource in double quotes. - Me.RecordSource = "table2"
It works perfect.
Thanks to all of you.
Glad we could help. Good luck on your project.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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...
|
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
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |