473,795 Members | 3,122 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

copy records mainform, subform1 & subform2

Hello there,

i have a main form to define products in.
i have a subform1 to fill in the related materials
i have a subform2 to fill in the machines to process the materials

subform1 is related to mainform through "ProductId" , subform2 is
related to subform1 through "MaterialId "
both subforms are displayed on the mainform.
i need to find out how i can copy a product-record including all
related records so i can make small adjustments in the "new" product
and save it as a new product.

i hope i made a bit clear what i mean ( my english/ jargon is not so
well)

any suggestions are welcome!!

thanks a lot in advance

Wout

Mar 27 '06 #1
4 1679
Hi!

Here's a procedure that works fine between two forms, a master and a
detail.
Why not just try and add a second sql string and see if u can update
the second subform. Haven't tried it my self

(Code worked out by Al Kallal)

Me.Name

Private Sub cmdCopy_Click()
On Error GoTo Err_Copy

Dim rs As DAO.Recordset
Dim sqlNew As String
Dim lngNewOrderID as Long

'Force a diskwrite of current record
Me.Refresh

Set rs = Me.RecordsetClo ne

With rs
..AddNew
!CustID = Me!CustID
!EmployeeID = Me!EmployeeID
!CarID = Me!CarID
..Update
End With

'Now get ID of this new order just added.
'Simply move to last record changed
rs.Bookmark = rs.LastModified
lngNewOrderID = rs!OrderID

'Now copy details to NEW OrderID
sqlNew = "INSERT INTO
tblOrderDetail( ItemID,Price,Am ount,Period,Art ,Anl,OrderID) " & _
"SELECT ItemID,Price,Am ount,Period,Art ,Anl," & lngNewOrderID & _
'Please notice: NO SPACE AFTER LAST FIELD but
'SPACE BEFORE NEXT FIELD
" FROM tblOrderDetails " & _
"WHERE OrderID = " & Me!OrderID
CurrentDb.Execu te sqlNew, dbFailOnError
Wout skrev:
Hello there,

i have a main form to define products in.
i have a subform1 to fill in the related materials
i have a subform2 to fill in the machines to process the materials

subform1 is related to mainform through "ProductId" , subform2 is
related to subform1 through "MaterialId "
both subforms are displayed on the mainform.
i need to find out how i can copy a product-record including all
related records so i can make small adjustments in the "new" product
and save it as a new product.

i hope i made a bit clear what i mean ( my english/ jargon is not so
well)

any suggestions are welcome!!

thanks a lot in advance

Wout


Mar 28 '06 #2
Hi there,

many thanks for your reply! i tried it, but unfortunately it won't
work.
maybe it helps if i tell you that the records in subform2 are the
details of the active record in subform1.
i made this work by creating an unbound textbox (called "MaterialId ")
which recordsource is set to "=Subform1!Mate rialId"
so if you click somewhere in subform1, subform2 displays the
corresponding processing machines

thanks in advance.....

Wout

Mar 30 '06 #3
Hi,

I have been searching and trying to created the following code. the
idea is to loop through subform1 and execute for every record an append
query to copy the records from subform2. the code creates a new record
in the main form, copies the related 1st record from subform1 and
copies the related records from subform2. if subform1 has more then one
record these records are not copied (the related records in subform2
are not copied either)
I think it must be something in the loop but i haven't found out what
it is yet.....

Any help is highly appreciated!!!
Thanks in advance....

Apr 3 '06 #4
Euhhh..., sorry here's the code:

Private Sub cmdCopy_Click()
On Error GoTo Err_Handler
Dim db As DAO.database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim lngPrId, lngVAL, lngGrId As Long

Set db = CurrentDb
Set rs = Me.frmGrondstof fen.Form.Record setClone
If Me.Dirty Then
Me.Dirty = False
End If

If Me.NewRecord Then
MsgBox "Selecteer een bestaand product."
Else
'kopieer hoofdrecord en voeg toe aan kloon
With Me.RecordsetClo ne
.AddNew
!PrNaam = Me.PrNaam
.Update
'bewaar de nieuwe primaire sleutel waarde
.Bookmark = .LastModified
lngPrId = !PrId

'kopieer gerelateerde records uit sfrmGrondstoffe n
If rs.RecordCount > 0 Then
lngVAL = rs.RecordCount
MsgBox "Er worden " & lngVAL & " grondstoffen
gekopieerd"

With rs
rs.MoveFirst
Do Until rs.EOF
With rs
.AddNew
!GrNaam =
Forms!frmProduc ten!frmGrondsto ffen!GrNaam
!PrId = lngPrId
.Update
' bewaar de nieuwe primaire sleutel waarde
.Bookmark = .LastModified
lngGrId = !GrId

strSQL = "INSERT INTO tblBewerkingen ( GrId, BewNaam )" &
"SELECT " & lngGrId & " As GrId, tblBewerkingen. BewNaam " & " FROM
tblBewerkingen WHERE ((([GrId])= " & Me!frmGrondstof fen!GrId & "));"
db.Execute strSQL
End With
rs.MoveNext
Loop
End With
Set rs = Nothing
Set db = Nothing
Else
MsgBox "Alleen productgegevens gekopieerd, er waren geen
gerelateerde grondstoffen en bewerkingen."
End If

'geef de gekopieerde record weer
Me.Bookmark = .LastModified
Me.frmGrondstof fen.Requery
Me.frmBewerking en.Requery
End With
End If

exit_handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description , ,
"cmdKopiëren_Cl ick"
Resume exit_handler

End Sub

Apr 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2507
by: Robin S. | last post by:
**Eric and Salad - thank you both for the polite kick in the butt. I hope I've done a better job of explaining myself below. I am trying to produce a form to add products to a table (new products). Tables: tblCategoryDetails CategoryID SpecID
2
1559
by: Mark | last post by:
I have a project management database and it has a form called Estimator that calculates the cost of about 10 parts to a project. You can change parameters, click a Calculate button and all the costs are recalculated. Estimator works great! One of the parts contains an itemized list of up to six components that can be added up to arrive at the cost of that part. The components are listed in a subform sort of like quantity, description and...
3
12504
by: Stewart | last post by:
Hi all! My (relatively small) database holds data on staff members and the projects (services) that they are assigned to. In my form frmStaff, I have a list of staff members - it is a continuous form. Each staff member is linked to a Service through a many-to-many relationship, using a junction table called jctStaffServices. I would like to place a Combo Box in frmStaff where you can 'filter' staff by the Service (i.e. ServiceName)...
19
3480
by: davidgordon | last post by:
Hi, I need some pointers/help on how to do the following if it possible: In my access db, I have the following: Tables: Products, Sub-Assembly, Product-Pack Table, Products
3
1878
by: colleen1980 | last post by:
There are two continuous subforms in main form. All are linked with ticketNum. When user comes to subform2. I need that Field3 of subform2 will automatically filled with field2 (field2 is a textbox) of subform1. Field3 is a listbox where i need that user has to select single or multiple values. control which i am using is a listbox in field3. How to i do that needs help. Thanks.
5
2103
by: NewtoAccess | last post by:
I have a MAINFORM with a Subform1 which has another subform2. I want to copy the 'PORT_ID' field from subform2 and paste it to MAINFORM field called 'PORTA'. I was thinking of having a button in subform2 which would copy and paste all at once.
3
9248
by: Richnep | last post by:
Hi all, I have tabbed subforms where I need to copy one field value from one subform over to another subform. Although I can run an update query to accomplish this I would like to do it through VBA. sub tables relationships are 1:N with the main table. So the recods display like this in the subform:
5
2623
by: JHite | last post by:
I’m using Access 2003 on Windows XP. I have a Mainform (Staff Entry) which displays an unbound combo box named ChooseStaff. The Row Source for this combo box is a SELECT of the UserIDs and Staffer Names from a table (Staffers) which contains staffers’ names and other info. When the user actually selects a Staffer Name from the dropdown combo box, the VBA routines for the combo box’s On Enter and After Update events take care of finding and...
3
1441
by: Kappucino XL | last post by:
Hey There... I have two datasheet subforms, on a mainform: Subform1 and subform2. They receive their info from two separate tables. Now, I need to copy information from subform1 to a field in subform2. Hope my Question is clear and not too stupid...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.