Originally posted by ashutoshvyas
Problem building ACCESS query for retrival of records.
Collapse
X
-
Originally posted by ADeziiI'm still working on it, please be patient.
NeoPa: (me writing)
Here is a little Off-The-Wall technique that I always use whenever I want Query results to be numbered sequentially starting from 1 regardless of any Sort Order on any Field or Fields, number of Fields, etc. It is a little radical but there seems to be no other way to achieve the same result. Please look at it and let me know what you think. This code must be run prior to executing the Query and it also involves adding a [Counter] Field to the underlying Table then executing the Query with this ([Counter]) as the very 1st Column. It creates a Recordset based on the very Query that you want to sequentially number and writes the incremental values to the [Counter] Field starting at position 1. I'm sure that it can be improved - I just know that it works.
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecord set("qryEmploye e", dbOpenDynaset)
Do While Not MyRS.EOF
intRecNo = intRecNo + 1
MyRS.Edit
MyRS![Counter] = intRecNo
MyRS.Update
MyRS.MoveNext
Loop
MyRS.Close[/CODE]
No matter what Criteria you specify for qryEmployee, and no matter how many Records are returned, they will always be numbered 1 to Recordset.Recor dCount.Comment
-
Originally posted by ADeziiIt just dawned on me that I had experienced a similar request from a Member a long time ago, and here is how I resolved his problem. The circumstances are quite different, and the solution is a little extreme, but there seemed to be no other viable options and this logic does, in fact, work. I don't think that something like this can be implemented in your specific case, but I'll show you anyway. If you have any other questions, feel free to ask:
[CODE=vb]Dim MyDB As DAO.Database, MyRS As DAO.Recordset, intRecNo As Integer
Set MyDB = CurrentDb()
Set MyRS = MyDB.OpenRecord set("qryEmploye e", dbOpenDynaset)
Do While Not MyRS.EOF
intRecNo = intRecNo + 1
MyRS.Edit
MyRS![Counter] = intRecNo
MyRS.Update
MyRS.MoveNext
Loop
MyRS.Close[/CODE]
No matter what Criteria you specify for qryEmployee, and no matter how many Records are returned, they will always be numbered 1 to Recordset.Recor dCount.
I had noticed that there is the word expert under your name which was moderator few days ago, so congrats for becoming expert.
Truly u r genius & expert. I like your way to support, that is the right way. Instead of giving straight forward answers u r giving answers in the form of hints or clever language. I like your art.
with the help of your last post i had reached to the solution and now successful generation of report is done with sequential numbers. I am providing the code for reference for others.
1) In command1 i have to select lock type = 4- batch optimistic.
2) code segment (VB)
If .rsCommand1.Rec ordCount > 0 Then
.rsCommand1.Mov eFirst
Dim intRecNo As Integer
Do While Not .rsCommand1.EOF
intRecNo = intRecNo + 1
.rsCommand1.Upd ate
.rsCommand1![Counter] = intRecNo
.rsCommand1.Upd ate
.rsCommand1.Mov eNext
Loop
Set rptashu.DataSou rce = DataEnvironment 1
rptashu.Show
Else
MsgBox "No Titles found"
End If
End With
End Sub
Thank you again.Comment
-
Originally posted by ashutoshvyasThank you again.
I had noticed that there is the word expert under your name which was moderator few days ago, so congrats for becoming expert.
Truly u r genius & expert. I like your way to support, that is the right way. Instead of giving straight forward answers u r giving answers in the form of hints or clever language. I like your art.
with the help of your last post i had reached to the solution and now successful generation of report is done with sequential numbers. I am providing the code for reference for others.
1) In command1 i have to select lock type = 4- batch optimistic.
2) code segment (VB)
If .rsCommand1.Rec ordCount > 0 Then
.rsCommand1.Mov eFirst
Dim intRecNo As Integer
Do While Not .rsCommand1.EOF
intRecNo = intRecNo + 1
.rsCommand1.Upd ate
.rsCommand1![Counter] = intRecNo
.rsCommand1.Upd ate
.rsCommand1.Mov eNext
Loop
Set rptashu.DataSou rce = DataEnvironment 1
rptashu.Show
Else
MsgBox "No Titles found"
End If
End With
End Sub
Thank you again.Comment
Comment