473,386 Members | 2,042 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,386 software developers and data experts.

Duplicate Only the Subform's Last Record--Not the Main

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 StaffID, and
the PK ID is StaffandIntsID. The subform's data is put into
jtblStaffandInts, which joins a Staff and Intervention tables:

So, here's what the data could look like in the table:

StaffandIntsID InterventionID StaffID RoleID

41 24 3 1
42 24 4 2
43 24 13 3
44 24 2 4
45 24 20 5
46 24 99 6

So, for a new Intervention entered (InterventionID = 25), the data may
look like

47 25 3 1
48 25 4 2
49 25 13 3
50 25 2 4
51 25 20 5
52 25 99 6

But, the user must be able to change the staff names, such as the
first record, StaffID = 3, to some other staff. And, users must be
able to delete a staff in the new record.

This subform is linked to another subform in the main form: child
field = InterventionID, master = [sfrmIntsPastDB].Form!
[InterventionID]

Thanks
Jul 28 '08 #1
3 1702
6a***************@gmail.com wrote:
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 StaffID, and
the PK ID is StaffandIntsID. The subform's data is put into
jtblStaffandInts, which joins a Staff and Intervention tables:

So, here's what the data could look like in the table:

StaffandIntsID InterventionID StaffID RoleID

41 24 3 1
42 24 4 2
43 24 13 3
44 24 2 4
45 24 20 5
46 24 99 6

So, for a new Intervention entered (InterventionID = 25), the data may
look like

47 25 3 1
48 25 4 2
49 25 13 3
50 25 2 4
51 25 20 5
52 25 99 6

But, the user must be able to change the staff names, such as the
first record, StaffID = 3, to some other staff. And, users must be
able to delete a staff in the new record.

This subform is linked to another subform in the main form: child
field = InterventionID, master = [sfrmIntsPastDB].Form!
[InterventionID]

Thanks
I know I don't understand the problem but...what the heck.

First, you could get the Max intervention ID. In this case it would be 24.
Dim strSQL As String
Dim dbs As Database
Dim MaxID As Long

MaxId = DMax("ID","YourTable")

'make an append query string to append the new records
strSQL = "INSERT INTO YourTable ( InterventID, StaffID, RoleID ) " & _
"SELECT " & MaxID + 1 & ", StaffID, RoleID " & _
"FROM YourTable " & _
"WHERE InterventID = " & MaxID

set dbs = currentdb
dbs.execute strSQL 'run the SQL statement

This will append all records from 24 into 25.
Jul 28 '08 #2
I appreciate it guys; I'll try it later tonight.
Jul 28 '08 #3
Here is my solution; thanks to your help. I put a cmd button
(cmdAppend) with the caption "Copy Staff to New Record" on the main
form. On its click event, I put this:

Dim strSQL As String
Dim dbs As Database
Dim PrevID As Long
Dim MaxID As Long

PrevID = Forms!frmInterventions.txtPreviousIntID 'Where on the
main form's open event, Me.txtPreviousIntID = Me!sfrmIntsPast.Form!
InterventionID (renamed the 'DB' subform from above)
MaxID = DMax("InterventionID", "qryStaffAndInts2") 'This query
filters interventions that are associated with only the current
student selected in main form

'make an append query string to append the new records
strSQL = "INSERT INTO jtblStaffAndInts ( InterventionID, StaffID,
RoleID ) " & _
"SELECT " & MaxID & ", StaffID, RoleID " & _
"FROM jtblStaffAndInts " & _
"WHERE InterventionID = " & PrevID

Set dbs = CurrentDb
dbs.Execute strSQL 'run the SQL statement

===============

cmdAppend's visible property is turned on/off depending on whether
there are any previous interventions entered for the student. So, I
hid a textbox, txtCount, in the footer of sfrmIntsPast that =
Count([InterventionID]).

Lastly, inside of sfrmIntsRecent, on the cmdbutton that 'saves and
goes to the staff subform,' I put:

If Me.Parent.txtCount = 0 Then
Me.Parent.cmdAppend.Visible = False
Else
Me.Parent.cmdAppend.Visible = True
End If
Aug 1 '08 #4

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

Similar topics

1
by: M Wells | last post by:
Hi All, I am developing an Access 2003 project application with the back end in SQL Server 2003. I have a master form that tracks projects, and several subforms on it that track various...
1
by: Richard Hollenbeck | last post by:
I have a main form for entering students' grades. The main form indicates which activity I will be entering. The sub form on the right contains the actual score for the activity. It is based...
5
by: Richard Stanton | last post by:
Hello all My database has a main form linked to table1. It has several subforms on the main form, all linked to table2. Table1 and Table2 are linked by primary/foreign key, no duplicates...
3
by: tlyczko | last post by:
I have a main form with 2 subforms, each subform references different data in the same table. How do I make sure each subform only creates NEW records in the referenced table and do not...
0
by: katedw203 | last post by:
I'd like to delete this post
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 #. ...
2
by: Constantine AI | last post by:
Hi can anybody help? I have a main form with customer details on that links to a sales order head subform through the customer ID. The sales order head subform is then linked to the sales order...
0
by: TD | last post by:
I have a main form with two subforms (both in datasheet view), neither of which are linked to the main form. The main form is based on a query that uses the bound column of a combobox on the main...
1
by: SirTKC | last post by:
Hi, Here is the following scenario. I do have a master table with related subforms from wich I need to create a revision. But I need to duplicate the content of the subforms and link them to...
1
by: AccessBeetle | last post by:
I am working with SQL server 2005 backend and Access 2003 frond end. I have a form bound to a table tblReportDetails. There are several(5) tabs on the same form. Each tab has its own subform. Every...
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:
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...
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
1
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...
0
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...
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
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
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...

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.