473,394 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Duplicate the record in form and subform

Hi,

I am not a programmer but tries anyway to program a feature in a form
where I am able to copy entries for the form and a subform. I have
tried follow the guide here http://allenbrowne.com/ser-57.html, but my
problem is that I have more than one keyfield in the join between the
two tables: Hovedoplysninger and Itemoplysninger. The tree fields are:
"Medarbejder", "Sagsnummer" and "Mandag". I have succeded creating the
new entry in "Hovedoplysninger" but the problem is the append-part
which should copy the items.

My code so far (I am told there are problems in the "INTO-syntax"
Thanks in advance!

Clucking.

Private Sub Kopier_Click()
´On Error GoTo Err_Handler
´Purpose: Duplicate the main form record and related records in
the subform.
´Dim strSql As String ´SQL statement.
Dim lngMedarbejder As Long ´Primary key value of the new
record.
Dim lngSagsnummer As String
Dim lngDato As Date

´Save and edits first
If Me.Dirty Then
Me.Dirty = False
End If
´Make sure there is a record to duplicate.
If Me.NewRecord Then
MsgBox "Vælg en record at kopiere."
Else
´Duplicate the main record: add to form´s clone.
With Me.RecordsetClone
.AddNew
!Medarbejder = Me.KopiTil
!Sagsnummer = Me.Sagsnummer
!Mandag = Me.Mandag
!PeriodeID = Me.PeriodeID
´etc for other fields.
.Update

´Save the primary key value, to use as the foreign key for
the related records.
.Bookmark = .LastModified
lngMedarbejder = !Medarbejder
lngSagsnummer = !Sagsnummer
lngDato = !Mandag

If Me.[Itemoplysninger
Underformular].Form.RecordsetClone.RecordCount 0 Then
strSql = "INSERT INTO [Itemoplysninger] ( Medarbejder,
Sagsnummer, Mandag, Indtastningsdato, Jobnummer, Linienummer,
Kundenummer, ManAntal, TirAntal, OnsAntal, TorAntal, FreAntal,
LørAntal, SønAntal, Udføring, Årsag, Antal, Enhed, Ekstraarb,
Godkendelsesflag, Aftaleseddel, AKK, Rekvirent ) " & _
"SELECT " & lngMedarbejder & " AND " & lngSagsnummer & "
AND " & lngDato & " As NwMedarbejder, As NwSagsnummer, As NwMandag,
Indtastningsdato, Jobnummer, Linienummer, Kundenummer, ManAntal,
TirAntal, OnsAntal, TorAntal, FreAntal, LørAntal, SønAntal, Udføring,
Årsag, Antal, Enhed, Ekstraarb, Godkendelsesflag, Aftaleseddel, AKK,
Rekvirent " & _
"FROM [Itemoplysninger] WHERE Medarbejder = " &
Me.Medarbejder & " AND Sagsnummer = " & Me.Sagsnummer & " AND Mandag =
" & Me.Mandag & ";"
DBEngine(0)(0).Execute strSql, dbFailOnError
Else
MsgBox "Main record duplicated, but there were no
related records."
End If

´Display the new duplicate.
Me.Bookmark = .LastModified
End With
End If

Exit_Handler:
Exit Sub

Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, ,
"cmdDupe_Click"
Resume Exit_Handler
End Sub

Jan 28 '07 #1
0 2497

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

Similar topics

9
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or...
1
by: Bert | last post by:
We are using MS Access97. Now by entering a new item to the database the problem occurs. We are using a subform and a form, by clicking a field in the subform the form produces an error regarding...
3
by: Donna Price | last post by:
I have a problem with a database which I've recently separated into several related tables. I have a main data entry form, which has several subforms on it on tabbed pages. The first subform is...
0
by: cmd | last post by:
Hi, I have a query based on Table-A which populates most of the pages of a tab control. On two of the pages, however, I would like to have fields from Table-B. There's too many fields in this...
2
by: mavmavv | last post by:
I have a Form where I have created a duplicate record button, no problem... The subform is where my problem lies. The subform displays data matching the mainform's ID, these two values are...
6
by: Otis492 | last post by:
Hello, I have been struggling with this for a while. I am working on a rather simple database for claims in Access 2003. I have a table called claims that has a primary key field called Claim #. ...
1
by: VinArt | last post by:
MS Acc 2003, XP Thank you in advance for any help. I have tables called "Makeup" and "Lines". Each makeup can have multiple lines. Goal is to create a new "makeup" with identical "lines"...
3
by: 6afraidbecause789 | last post by:
Kudos to anyone who can explain this one--how to duplicate a group of continuous records in a subform for use in a new subform PK ID. The 2 entry fields (combo boxes) in the subform are RoleID and...
1
by: xraive | last post by:
I have a problem with this. Currently I am trying Allen's code and i am not successful. Current Design Table1 (Main Form) TravelID (PK) ApprovedBY EntreredBy BudgetCode ExpenseCode
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
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...
0
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
Oralloy
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,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.