Im using the following code to duplicate a record varCnt(retrieved from a combo box on the form) many times, and it only duplicates the record with the fields present on the form for that record.
The duplicate fields are [childs name] and [target 1] [target 2] (upto target 5) and then it duplicates the [weekly index] but adds 1 to each duplicate for this field.
But if the targets are updated again it keeps the old duplicates for future weeks, causing there to be 2 sets of records for those future weeks.
So ive added a bit to the code when they are added to search for duplicates, but what it does is delete all but the last updated record.
But what i need it to do is not to delete the last updated record, but the last varCnt record, so in other words if varCnt is 3, then it deletes all but the last 3.
heres the code, i reckon this must be quite simple, but i cant work it out, ive tried playing around a bit, but im not a coder: -
Private Sub Command16_Click()
-
On Error GoTo Err_Command16_Click
-
Dim i As Integer, cnt As Integer, varBk As String
-
Dim intCriteriaCount As Integer, MyDB As Database, MyRS As Recordset
-
Dim intCounter As Integer
-
-
varBk = Me.Bookmark
-
cnt = Me!Combo17
-
-
For i = 0 To cnt - 1
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70 'Paste Append
-
-
Me!Text22 = Me!Text22 + 1
-
-
Next
-
-
Exit_Command16_Click:
-
Me.Bookmark = varBk
-
-
intCriteriaCount = DCount("*", "FindDuplicatesWeeklyPoints")
-
-
'Are there Records meeting the Criteria?
-
If intCriteriaCount > 0 Then
-
Set MyDB = CurrentDb()
-
'Order by your Primary Key Ascending
-
Set MyRS = MyDB.OpenRecordset("SELECT * FROM FindDuplicatesWeeklyPoints ORDER BY [Weekly Index]")
-
MyRS.MoveLast: MyRS.MoveFirst
-
For intCounter = 1 To intCriteriaCount - 1 'All but the Last Record
-
MyRS.Delete
-
MyRS.MoveNext
-
Next
-
Else
-
Exit Sub
-
End If
-
-
MyRS.Close
-
-
Exit Sub
-
-
Err_Command16_Click:
-
MsgBox Err.Description
-
-
Resume Exit_Command16_Click
-
-
End Sub
-
thanks
Adam
1 1192
Hi Adam,
Will this work ... -
Private Sub Command16_Click()
-
On Error GoTo Err_Command16_Click
-
Dim i As Integer, cnt As Integer
-
Dim varBk As String
-
Dim intCriteriaCount As Integer
-
Dim MyDB As Database
-
Dim MyRS As Recordset
-
Dim intCounter As Integer
-
-
varBk = Me.Bookmark
-
cnt = Me!Combo17
-
-
For i = 0 To cnt - 1
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 2, , acMenuVer70
-
DoCmd.DoMenuItem acFormBar, acEditMenu, 5, , acMenuVer70
-
-
'Paste Append
-
Me!Text22 = Me!Text22 + 1
-
-
Next
-
-
Exit_Command16_Click:
-
Me.Bookmark = varBk
-
-
intCriteriaCount = DCount("*", "FindDuplicatesWeeklyPoints")
-
-
'Are there Records meeting the Criteria?
-
If intCriteriaCount > 0 Then
-
Set MyDB = CurrentDb()
-
'Order by your Primary Key Ascending
-
Set MyRS = MyDB.OpenRecordset("SELECT * FROM FindDuplicatesWeeklyPoints ORDER BY [Weekly Index]")
-
MyRS.MoveLast: MyRS.MoveFirst
-
For intCounter = 1 To intCriteriaCount - cnt 'All but the Last Record
-
MyRS.Delete
-
MyRS.MoveNext
-
Next
-
Else
-
Exit Sub
-
End If
-
-
MyRS.Close
-
-
Exit Sub
-
-
Err_Command16_Click:
-
MsgBox Err.Description
-
-
Resume Exit_Command16_Click
-
-
End Sub
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: wired |
last post by:
Hi,
I've just taught myself C++, so I haven't learnt much about style or
the like from any single source, and I'm quite styleless as a result.
But at the same time, I really want nice code and I...
|
by: free2cric |
last post by:
Hi,
I attanded an interview on C++
Question asked were and my answers to them..
1. In a CPP program what does memory leak occure?
-- i said.. In a constructor , the pointer variables were...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Colin McGuire |
last post by:
I apologize for posting yet another scrollbar question. Here is my
code. All I want is for a diagonal line to appear from coordinates
(0,0) to (width,height) in a usercontrol regardless of whether...
|
by: Peter Olcott |
last post by:
Cab you write code directly in the Common Intermediate language? I need to
optimize a critical real-time function.
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: user923005 |
last post by:
It would be really nice if C could adopt a really nice algorithms
library like C++'s STL + BOOST.
The recent "reverse the words in this sentence" problem posted made me
think about it.
It's...
|
by: Dave |
last post by:
I'm having a hard time tying to build gcc 4.3.1 on Solaris using the GNU
compilers. I then decided to try to use Sun's compiler. The Sun Studio
12 compiler reports the following code, which is in...
|
by: raylopez99 |
last post by:
I ran afoul of this Compiler error CS1612 recently, when trying to
modify a Point, which I had made have a property. It's pointless to
do this (initially it will compile, but you'll run into...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: 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: 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,...
|
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,...
|
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...
| |