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

Deleted select records from recordset

294 256MB
Hi all,

I'm attempting to write some VBA code. I am creating an append query on the click of a button, which will also run this code. Under the first two conditions, I want the records to stay in the InvalidElectionTbl, and those that do not should be deleted from the table. This table will be used for reporting invalid selections, nothing else.

Does this look right? (Note: I am concerned with the rs.delete aspect of this, however if anything else looks funny please let me know)

Expand|Select|Wrap|Line Numbers
  1. Dim rs As DAO.Recordset
  2. Dim db As Database
  3. Dim dob As Date
  4. Dim ElectionDate As Date
  5. Dim plan As Integer
  6. Dim age As Integer
  7.  
  8. Set db = CurrentDb
  9. Set rs = db.OpenRecordset("SELECT * FROM InvalidElectionTbl")
  10.  
  11.     If rs.BOF And rs.EOF Then
  12.         'Do nothing, recordset is empty
  13.     Else
  14.         dob = rs!DateOfBirth
  15.         ElectionDate = rs!ElectionDate
  16.         plan = rs!PlanID
  17.         age = CalcExactDiff(dob, ElectionDate)
  18.  
  19.         If age < 55 And plan = 1 Or 3 Then
  20.             'do nothing
  21.         ElseIf age < 48 And plan = 2 Then
  22.             'do nothing
  23.         Else
  24.             rs.Delete
  25.         End If
  26.  
  27.     rs.Close
  28.  
And of course - thank you.
Dec 9 '13 #1
5 1081
Rabbit
12,516 Expert Mod 8TB
Why do this through traversing a recordset instead of through a query?
Dec 9 '13 #2
mcupito
294 256MB
Because I have to concatenate two tables (sorry I didn't explain that)
Dec 9 '13 #3
Rabbit
12,516 Expert Mod 8TB
You can still do that with queries.
Dec 9 '13 #4
mcupito
294 256MB
Are queries more efficient or something? while I do not disagree, I'm not sure why you are guiding me down the other path.
Dec 9 '13 #5
Rabbit
12,516 Expert Mod 8TB
Queries are much more efficient than processing row by row.
Dec 9 '13 #6

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

Similar topics

3
by: William Gill | last post by:
I can't help but think I'm re-inventing the wheel if I have to code my own interface! Isn't there some script, php code, or something (modifiable / customizable) available that lets me select...
2
by: Danny | last post by:
How to allow users to select a set of records and then let them change a field for all these records at once? I would like to do this in code on a form. I will have a form with tabular view of...
1
by: arthur-e | last post by:
How can you select records based on more than one combo box - I have a combobox that selects records based on name (I'm sure this has been asked a thousand times - web site answer/link could be...
1
by: Dan Sikorsky | last post by:
How do you select records from one dataset and create a second dataset? I need to pull out the master records from a dataset and create a master datagrid in which to embed a details datagrid (for...
1
by: francophone77 | last post by:
What is the best way to setup a query to select records in specific months only. For instance if I want to compare sales in the month of May regardless of year. TIA
5
by: Chris Cowles | last post by:
I use an application that uses Oracle 8.1.7. All functions of the application are completed with calls to stored procedures. A data entry error occurred that caused thousands of records to be...
2
by: Hamayun Khan | last post by:
Hi all I am using the following query to select records for table Select JobTitle,JobDesc,Scraped,logoimage,JobPostID,SchoolID,web,MemType,InstitutionName,PayScale,LEA,Contract as...
2
by: rkferguson | last post by:
Hi Folks, I have a table that captures information about documents that leave the office. Some of those documents may get a signature and then return to the office. Need away to query the...
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
0
by: Elizabeth Mitte | last post by:
Hello, Thank you for the tutorial type article, is proving very useful. However, I have been following your instructions step by step and still get errors with the code? Trying to create the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.