473,382 Members | 1,336 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,382 software developers and data experts.

Marking a record without bookmark?

Hi,

I am trying to evaluate data in a table. First I need to evaluate NotionalValue for Symbols that match. If it passes my parameters, I need to apply my "flags" to the flag field. Instead of using so many rst.moveprevious and rst.movenext commands, is there a better way to "tag" a record so that I can return to it? I do not have a key field...symbol is my unique field. Also, with my current code, I am getting a "No Current Record" error message at the "*****" I know that the rst!Symbol is at the rst!movefirst position, but for some reason my rst.BOF is not true...any thoughts here too? Thanks so much!

[code]
Private Sub cmbApplyFlag_Click()
Dim db As DAO.Database
Dim rst As DAO.Recordset
Dim mNV1, mNV2, mTQ1, mTQ2, mRate1, mRate2 As Double
Dim counter, mUnder, mOver, i As Long
Dim curSymbol, BM As String

Set db = CurrentDb()
Set rst = db.OpenRecordset("TEMPLongShort")
counter = 0
mUnder = 0
mOver = 0

If rst.BOF And rst.EOF Then
MsgBox "No records to process"
Else
rst.MoveFirst

Do Until rst.EOF
curSymbol = rst!Symbol
BM = rst.Bookmark
Debug.Print BM
Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
Do While rst!Symbol = curSymbol
If rst!NotionalValue > 1000000 Then
mOver = mOver + 1
ElseIf rst!NotionalValue < 1000000 Then
mUnder = mUnder + 1
End If
counter = counter + 1
rst.MoveNext
BM = rst.Bookmark
Debug.Print BM
Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
Loop
rst.MovePrevious
Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
If counter = mUnder Or counter = mOver Then
rst.MoveNext
Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
Else
Debug.Print rst!Symbol, rst!NotionalValue
Debug.Print curSymbol
Do While rst!Symbol = curSymbol
If rst!NotionalValue > 1000000 Then
rst.Edit
rst!Flag = "$"
rst.Update
Else
rst.Edit
rst!Flag = "M"
rst.Update
End If
If rst.BOF Then
Exit Do
Else
rst.MovePrevious
*****Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
End If
Loop
For i = 1 To (counter + 1)
rst.MoveNext
Debug.Print curSymbol & " " & rst!NotionalValue & " " & rst!Symbol
Next
End If
counter = 0
mUnder = 0
mOver = 0
Loop
End If
db.Close
rst.Close
Set db = Nothing
Set rst = Nothing
End Sub
[ENDCODE]
Apr 5 '07 #1
6 1861
MMcCarthy
14,534 Expert Mod 8TB
Firstly, instead of using ENDCODE use /CODE to closed the code tags.

I can't follow the logic of your code. Can you explain what you are doing here and why.

Mary
Apr 6 '07 #2
I am basically cycling through records in a table. I need to perform some analysis and then depending on what happens here I need to perform a different analysis on the same subgroup of records. I thought I would use the bookmark 'function', but have been unsuccessful. The work around I found was using rst.moveprevious by my variable 'counter'. Sorry for being unclear.
Apr 9 '07 #3
maxamis4
295 Expert 100+
The best answer for this is an array. You would store the values that meet your criteria an array. When your first pass is through and you need to get more information on the subset of numbers you use the array as the table to reloop through the recordset.

What exactly are you trying to do. I know you explained what it suppose to do, but could you explain the purpose?
Apr 9 '07 #4
jamjar
50
If you're trying to find a subset of records to process, could you use and SQL statement to retrieve the records meeting your criteria (say, over $1000000) rather than evaluating each record through code? James
Apr 10 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
I am basically cycling through records in a table. I need to perform some analysis and then depending on what happens here I need to perform a different analysis on the same subgroup of records. I thought I would use the bookmark 'function', but have been unsuccessful. The work around I found was using rst.moveprevious by my variable 'counter'. Sorry for being unclear.
From a logic point of view think of using two recordsets.
Expand|Select|Wrap|Line Numbers
  1. Dim db As Database
  2. Dim rs1 As Recordset
  3. Dim rs2 As Recordset
  4.  
  5. Set db = CurrentDb
  6. Set rs1 = db.OpenRecordset("TEMPLongShort")
  7.  
  8. rs1.MoveFirst
  9. Do Until rs1.EOF
  10.    ' Act on record here?
  11.    Set rs2 = db.OpenRecordset("SELECT * FROM TEMPLongShort WHERE Symbol=" & rs1!Symbol)
  12.       rs2.MoveFirst
  13.       Do Until rs2.EOF
  14.          ' Act on subset of records here.  
  15.          ' If you would like to remove these records from further action 
  16.          ' add a checkbox field and set to true to eliminate them.  Don't 
  17.          ' forget to check subsequent records for the value of this field
  18.          rs2.MoveNext
  19.       Loop
  20.    rs1.MoveNext
  21. Loop
  22.  
  23. rs1.Close
  24. rs2.Close
  25. Set rs1 = Nothing
  26. Set rs2 = Nothing
  27. Set db = Nothing
  28.  
Mary
Apr 10 '07 #6
Thank you for your ideas...I have thought of this approach too. It seems so inefficient as I will only have 2-5 records in the subset at a time. I was hoping I could MARK the start and end of a new group of records (I have sorted my list so all matching symbols will be together) and return to the start point and RST.MOVENEXT through the list again and again as need be. I thought using a bookmark like feature could work, any thoughts on this or should I just use your suggestion of 2 recordsets.

Thanks again!
Apr 10 '07 #7

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

Similar topics

4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
1
by: Skully Matjas | last post by:
Thank you for getting back to me. I am very new at this so i didnot understand what you said, here i will give as much cetails as possible: 1) The combo box i am using is combox39 2) I imported...
2
by: Norman Fritag | last post by:
Hi there, On a form I click a tickbox ("display",yes/No) that requires the recordset. =>>Code<<-- Me!PositionClosingDate = Format(Date, "Short Date") ' when was the position closed? Me.Requery...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
3
by: J | last post by:
I've moved the database tables from the .mdb file to Sql Svr and now I have an *intermittent* problem. When I select a record from a combo box, it will intermittently pull up the wrong record. ...
8
by: Zlatko Matić | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
8
by: MLH | last post by:
Before running the following line of code, I would like to first know if there is another record in the form's record source. If I run this line when the last record is current, an error is...
2
by: Robert | last post by:
I have a label on my form lblCount and the following code in my form for displaying a record count: Private Sub Form_Current() Me.RecordsetClone.Bookmark = Me.Bookmark Me!lblCount.Caption =...
10
by: MLH | last post by:
Suppose, in a multi-user environment, you have append query SQL in a VBA procedure that looks like INSERT INTO MyTable... and the next line reads MyVar=DMax("","MyTable... You can never be...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
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...

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.