mehmet
Sep 3rd, 2004, 02:02 PM
I'm using Access 97 and have a table (named "tblCompiledSorted") where records are set up like this:
Record No | Identifier
-------------------------------
1 12
2 14
3 14
4 17
5 19
6 19
I'm trying to write a module to change all my "Record No" change to "010" unless the identifier directly below the current row is identical to the identifier directly above it, in which case I want it named "012". Basically, I want my table to look like this when it's done:
Record No | Identifier
-------------------------------
010 12
012 14
010 14
010 17
012 19
010 19
Here's the code I wrote to try and do this:
Public Function UpdateRecordNo()
Dim db As Database
Dim strsql As String
Dim rstTop As Recordset, rstBottom As Recordset, rstRecNum As Recordset
Dim strTop As String, strBottom As String, strRecNum As String
Set db = CurrentDb
'Establish rstTop
strsql = "SELECT Identifier FROM tblcompiledsorted"
Set rstTop = db.OpenRecordset(strsql)
strTop = rstTop.Fields("Identifier").Value
'Establish restBottom
strsql = "SELECT Identifier FROM tblcompiledsorted"
Set rstBottom = db.OpenRecordset(strsql)
rstBottom.MoveNext
strBottom = rstBottom.Fields("Identifier").Value
'Establish rstRecNum
strsql = "SELECT * FROM tblcompiledsorted"
Set rstRecNum = db.OpenRecordset(strsql)
strRecNum = rstRecNum.Fields("Identifier").Value
'label Record Numbers
Do While rstRecNum.EOF = False
With rstRecNum
If strTop = strBottom Then
.Edit
![Record No] = "012"
.Update
Else
.Edit
![Record No] = "010"
.Update
End If
End With
rstTop.MoveNext
rstBottom.MoveNext
rstRecNum.MoveNext
Loop
rstTop.Close
rstBottom.Close
rstRecNum.Close
End Function
The problem is, when I run this I get a "No current record" message for the rstBottom.MoveNext command that in the looping section. Since it won't move to the next record, it pretty much screw my entire bit of code. I'm assuming it's because of the rstBottom.MoveNext I have in the 'Establish rstBottom section, but I haven't quite figured that out yet.
Does anyone know why this is happening or have any ideas on how I can fix it? I'd like to salvage this bit of code if possible as starting over would be rather vexing. Thanks in advance!
Record No | Identifier
-------------------------------
1 12
2 14
3 14
4 17
5 19
6 19
I'm trying to write a module to change all my "Record No" change to "010" unless the identifier directly below the current row is identical to the identifier directly above it, in which case I want it named "012". Basically, I want my table to look like this when it's done:
Record No | Identifier
-------------------------------
010 12
012 14
010 14
010 17
012 19
010 19
Here's the code I wrote to try and do this:
Public Function UpdateRecordNo()
Dim db As Database
Dim strsql As String
Dim rstTop As Recordset, rstBottom As Recordset, rstRecNum As Recordset
Dim strTop As String, strBottom As String, strRecNum As String
Set db = CurrentDb
'Establish rstTop
strsql = "SELECT Identifier FROM tblcompiledsorted"
Set rstTop = db.OpenRecordset(strsql)
strTop = rstTop.Fields("Identifier").Value
'Establish restBottom
strsql = "SELECT Identifier FROM tblcompiledsorted"
Set rstBottom = db.OpenRecordset(strsql)
rstBottom.MoveNext
strBottom = rstBottom.Fields("Identifier").Value
'Establish rstRecNum
strsql = "SELECT * FROM tblcompiledsorted"
Set rstRecNum = db.OpenRecordset(strsql)
strRecNum = rstRecNum.Fields("Identifier").Value
'label Record Numbers
Do While rstRecNum.EOF = False
With rstRecNum
If strTop = strBottom Then
.Edit
![Record No] = "012"
.Update
Else
.Edit
![Record No] = "010"
.Update
End If
End With
rstTop.MoveNext
rstBottom.MoveNext
rstRecNum.MoveNext
Loop
rstTop.Close
rstBottom.Close
rstRecNum.Close
End Function
The problem is, when I run this I get a "No current record" message for the rstBottom.MoveNext command that in the looping section. Since it won't move to the next record, it pretty much screw my entire bit of code. I'm assuming it's because of the rstBottom.MoveNext I have in the 'Establish rstBottom section, but I haven't quite figured that out yet.
Does anyone know why this is happening or have any ideas on how I can fix it? I'd like to salvage this bit of code if possible as starting over would be rather vexing. Thanks in advance!