473,418 Members | 4,041 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,418 software developers and data experts.

How to delete a record from recordset but not from table

I am trying to load certain data from a table into a recordset and then working with it without affecting the data in the tables.

The idea is to post all records in a table (given a certain criteria) randomly one by one, and when one has been displayed, it needs to be deleted from the recordset (but not the table!) so it does not randomly show up again.

My problem thus being, if I use rst.delete it will not just delete the record in my recordset, but also the data in the table. Is it possible to create such a unlinked set of records where you can modify as you please without affecting database data?

I use the following code to load up my recordset:

Expand|Select|Wrap|Line Numbers
  1.  Set rst = db.OpenRecordset("SELECT * FROM tblVragen WHERE categoriecode = '" & strCategoriecode & "'") 
thanks!
Jul 26 '10 #1
9 4181
amitpatel66
2,367 Expert 2GB
Why dont you try to order by <something> and loop the the records in recordset till the last record is reached and process those one by one?
Jul 26 '10 #2
Thanks for the incredibly quick reply ;). Well, order by only grants a limited way of randomizing things doesn't it? Or can you order in more ways than I know?

Let me explain the full thing, I'm trying to make an application where a question pops up, the user answers, it says it's either a good or wrong answer and moves on to the next question. Everytime the user launches this application the questions have to be in a different random order. So I put in a randomizer to select a record randomly and display that.

The problem with that is that the same record can pop up multiple times. That's why I thought I'd just delete a record from my recordset that's already been displayed so it wouldn't pop up again. But of course I don't want to lose that question from the table.
Jul 26 '10 #3
hype261
207 100+
@Will The Gray
Have you thought of making a temporary table to store the recordset that way it doesn't matter if they are deleted or not?
Jul 26 '10 #4
Yeah thought about it, but hoped there would be an easier way ;)
Jul 26 '10 #5
hype261
207 100+
@Will The Gray
How is your randomizer set up?

I am assuming that your randomizer is a function in vba that randomizes the order in the recordset. If so couldn't you just do Order By the randomizer. Here is a very simple sample that I put together

Expand|Select|Wrap|Line Numbers
  1. SELECT test.pk, test.test, randomizer([pk]) AS Random
  2. FROM test
  3. ORDER BY randomizer([pk]);
radomizer is just a function in VBA that I have built

Expand|Select|Wrap|Line Numbers
  1. Public Function randomizer(pk As Integer) As Integer
  2.  
  3.   randomizer = Rnd * 100 * pk
  4.  
  5. End Function
This should change the order of the questions every time and you can use a forward only cursor to go from first to last.
Jul 26 '10 #6
NeoPa
32,556 Expert Mod 16PB
Apply a filter to your recordset, or include the filter in the WHERE clause.

How your recordset is used determines whether or not the recordset needs to be re-opened.
Jul 26 '10 #7
Must admit I'm not entirely following. Tried the randomizer thing but it says the function isn't defined, although it is set as a public function.

Is it possible to give me a more concrete example using my code below? The categorycode of the question is selected beforehand, as you can see I just move to a random record with this code (and after an answer is given, it does it again). I understand I'm supposed to just order the recordset randomly and move through it instead of doing it this way, but I'm still in the dark on how to do that exactly. As far as I know ordering by simply takes a value and orders it ascending or decending from there on, which wouldn't be a strong randomizer as one question would always follow before or after another.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Set rsQuestions = db.OpenRecordset("SELECT * FROM tblQuestions WHERE Categorycode = '" & strCategorycode & "'")
  4.  
  5.     rsQuestions.MoveLast
  6.     MaxQuestions = rsQuestions.RecordCount
  7.     intNumber = CInt(Int(MaxQuestions * Rnd() + 1))
  8.     rsQuestions.MoveFirst
  9.     rsQuestions.Move (intNumber)
  10.  
Jul 27 '10 #8
Never mind I figured it out by using the order by randomizer thing.

Thanks a bunch :)
Jul 27 '10 #9
NeoPa
32,556 Expert Mod 16PB
A new thread with a question related to code posted in here was split from here and has been set up as Questions on Randomising.
Jul 28 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Kenneth Osenbroch | last post by:
Hi. I want to create a trigger that only allows delete from table A if corresponding record in table B does not exist. Any idea on how this can be done? Thanks, Kenneth.
3
by: Uwe Range | last post by:
Hi to all, I am displaying a list of records in a subform which is embedded in a popup main form (in order to ensure that users close the form when leaving it). It seems to be impossible to...
0
by: Mark | last post by:
All, Excuse the re-post but I have found something which works for the UserID but not for the Password (see previous post below). The problem is I don't understand how it works and therefore...
2
by: schapopa | last post by:
Hi, I have a contextmenu when user right click on the datagrid first column - delete row from datagrid. My code for that looks like this: Private Sub MenuItem1_Click(ByVal sender As...
1
by: gaurkamal | last post by:
I want to delete record in table B when i delete record in Table A both table have a common column. I want to do it using trigger .Can any body give some idea. Table details are. Table A: ...
4
by: barkarlo | last post by:
I use check box in a form "frmworkorder" like confirmation that's record finish. How can I write code who will block edit and delete record in form when is check box confirmed.
1
by: Bob | last post by:
Hello, Using VB 2005.net. I have a bound datagridview and a delete button control (or when the user pressed the 'Delete' key) I can successfully delete the selected record from the table and...
1
by: CreativeMind | last post by:
hi all, private void dgMygrid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { Button bDelete=(Button)e.Item.FindControl("btnDelete"); if(bDelete!=null) {...
5
by: saga git | last post by:
how to display nth record from table
9
mseo
by: mseo | last post by:
hi, I have a form for delete fitered records, i need to delete the main table's record if the child has no records thank you in advance for any help you may provide me
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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...
0
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,...
0
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...

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.