I have a button on a form that creates a new record, based on the current record, when the user clicks the button. The original code from the MASTER table worked fine. Now I need to add additional fields to the new record from another table: Related. When I added the code for the Related table, the fields in the Related table did not populate on the new record. Can someone please help? The code is below. Thanks - Private Sub Add_Click()
-
Dim db As DAO.Database
-
Dim rs As DAO.Recordset
-
Dim rs2 As DAO.Recordset
-
-
On Error Resume Next
-
-
Set db = CurrentDb
-
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [MASTER]")
-
rs.AddNew
-
rs![Number] = Me. Number.Value
-
rs![Title] = Me.Title.Value
-
rs![Year] = Me.Year.Value
-
rs![Schedule] = Me.Schedule.Value
-
rs![Comments] = Me.Comments.Value
-
rs![Statement] = Me.Statement.Value
-
rs![HistoryChanges] = Me.HistoryChanges.Value
-
rs![Orig_PubDate] = Me.Orig_PubDate.Value
-
rs![Last_PubDate] = Me.Last_PubDate.Value
-
rs![Keywords] = Me.Keywords.Value
-
rs.Update
-
rs.Close
-
db.Close
-
Set rs = Nothing
-
-
Set db = CurrentDb
-
Set rs2 = CurrentDb.OpenRecordset("SELECT * FROM [Related]")
-
rs2.AddNew
-
rs2![Related_1] = Me.Related_1.Value
-
rs2![Related_2] = Me.Related_2.Value
-
rs2![Related_ 3] = Me.Related_3.Value
-
rs2![Related_ 4] = Me.Related_4.Value
-
rs2![Related_ 5] = Me.Related_5.Value
-
rs2.Update
-
rs2.Close
-
Set rs2 = Nothing
-
-
db.Close
-
DoCmd.Close
-
End Sub
-
7 4801 zmbd 5,501
Expert Mod 4TB - rs2![Related_1] = Me.Related_1.Value
-
rs2![Related_2] = Me.Related_2.Value
-
rs2![Related_ 3] = Me.Related_3.Value
-
rs2![Related_ 4] = Me.Related_4.Value
-
rs2![Related_ 5] = Me.Related_5.Value
-
Note the spaces between the underscore and the numerics 3 thru 5? Was that intentional as there is no such space for 1 and 2.
By, simply stating that your code "doesn't work," not posting the error along with code (and omitting on which line the error occured), that appears to have had very little if any troubleshooting performed, and expecting someone to help doesn't usually result in much of an answer and may result in your thread being deleted.
@zmbd
Hi zmbd,
My mistake! The original code does not have the spaces. I don't get an error. I tried to create a record using this code, but only part of the new record was created. The fields in the Related table did not pull over to the new record and I don't know why. I am sorry if this is vague. Thanks
zmbd 5,501
Expert Mod 4TB
You should double check that all of your Me.Related_1.Value type lines are actually returning what you think they are... debug.print them out and check the immedate window by pressing <ctrl><g>
Why are you duplicating data between tables, that isn't done in a > Normalized Table Structures.
I guess what I am asking is the structure of my code right, assuming I have all of the table/field names correct? If it is, then I will have to find the problem somewhere else. I'm not sure why the new record does not include the fields Related_1, Related_2, etc.
Hi zmdb,I am not duplicating data between tables. I am pulling data from both tables on a form using a query. I then need to create a new record with most of the fields on the form. The reason is so that the users don't have to re-enter the same data on the new record as only a few fields are being changed on the new record.
Thanks zmbd. Good information. I will read through this and try and fix my code. I appreciate your help
Sign in to post your reply or Sign up for a free account.
Similar topics
by: vector |
last post by:
I want to dynamically create tables in a SQL Server 2000 database that
are modelled after XML schemas. I will not know what the schemas
might look like until the documents arrive.
For example,...
|
by: ApexData |
last post by:
I have 2 tables: Table1 and Table2.
Neither one has a primary key because each table will only have
1-record.
My form is a SingleForm unbound with tabs (my desire here).
Using this form, in...
|
by: elainenguyen |
last post by:
I am trying to write a code that seaching a record in 3 tables and if the record exist, show the data, if the record doesn't exist, show the warning message.
The following is my code that I am...
|
by: rbg |
last post by:
I am using derived tables to Page data on the SQL Server side.
I used this link as my mentor for doing paging on the SQL
Serverhttp://msdn2.microsoft.com/en-us/library/ms979197.aspx
I wanted to...
|
by: ApexData |
last post by:
Hello
I currently Link the FE/BE using the LinkTables Option and the Linked
Table Manager. Any time I need to move the BE to another location, I
have to go through this process over again. I...
|
by: biolie1984 |
last post by:
Plz Help me guys...
I want to delete a record from defferent tables e.g.
tb1 is a parent table
tb2 , tb3 , tb3 are a child table
then if i want to delete the parent the record from...
|
by: pkpanda |
last post by:
I have similar but bit different issue that is
I have a table INVOICE when user enter data in invoice I have to insert record into Transactions (Master ) and Transaction_details (detail) both...
|
by: Big Daddy |
last post by:
I am trying to do all my DB access through LINQ. For example, I am
trying to delete a record from the JobQueue table. There’s a couple
ways I could do this:
1. Method 1 – The disadvantage is...
|
by: CD Tom |
last post by:
I found Stephen Lebans modReportToPDF and have been trying to get it to work in my application. I've downloaded his database and when I run his test it works fine. I then added it to my application...
|
by: sknaina |
last post by:
Hi Eveybody,
I've a main form with a continuous subform based on 'DonorTranSmasterF' & 'DonorTranSdetailsF' ,
both tables are linked via 'DonorTransiD' field. I know & learn , How to save record...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |