MattBaldry
Self Taught, Learn from the Forums
- Local time
- Today, 16:10
- Joined
- Feb 5, 2019
- Messages
- 370
Hi All,
I have a code I use that I found on here, I was sure it was done by @isladogs , but I cannot find where anymore.
It is a function to move items up and down in a list box by changing a sequence field using buttons for up and down.
It works perfectly, I use it in lots of places. What I wanted to know would be how to change it to have the sequence based on 2 fields.
At the moment the sequence is based on every record in the table. What I am hoping to achieve is changing the list to a sequence grouped on a second field.
I may have the wrong author of the original code, I just cannot seem to find the website I found it the first time round.
~Matt
I have a code I use that I found on here, I was sure it was done by @isladogs , but I cannot find where anymore.
It is a function to move items up and down in a list box by changing a sequence field using buttons for up and down.
Code:
Dim varCurrentValue As Variant
Dim intCurrentSort As Integer
Dim strSQL As String
varCurrentValue = lst.Column(lst.BoundColumn - 1)
intCurrentSort = lst.Column(1, lst.ListIndex - lst.ColumnHeads)
strSQL = "UPDATE [" & TableName & "] " _
& "SET [" & SortField & "] = (2 * " & intCurrentSort & ") + " & Direction & " - [" & SortField & "] " _
& "WHERE [" & SortField & "] BETWEEN " & intCurrentSort & " AND " & intCurrentSort + Direction
CurrentDb.Execute strSQL, dbFailOnError
lst.Requery
lst.Value = varCurrentValue
It works perfectly, I use it in lots of places. What I wanted to know would be how to change it to have the sequence based on 2 fields.
At the moment the sequence is based on every record in the table. What I am hoping to achieve is changing the list to a sequence grouped on a second field.
| GroupID | Sequence |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 2 | 3 |
| 2 | 4 |
| 3 | 1 |
| 3 | 2 |
I may have the wrong author of the original code, I just cannot seem to find the website I found it the first time round.
~Matt