Solved Is there another way to sort ascending and descending numbers?

Matin_Murad

Member
Local time
Today, 05:23
Joined
Jul 1, 2020
Messages
37
I want ascending: 1, 2, 3, 4, 10, 11, 101, 121, 133 without using queries
 

Attachments

Well if you didn't have 10 and 101 in there, you could use text and sort that.
 
you don't need to use queries to sort - user can use the right click menu on a table, query or form or you can use the form order by and order by on load properties . Reports ignore any sorting done in a recordsource ahd you have to use the group by/sort by functionality provided by reports.

As far as your sample db is concerned, change the datatype from text to number
 
I don't want to go to a table and then right-click sort and sort
And I do not want to change the data type to a number. There are letters with numbers
I want to sort data with a button and a click
 
There are letters with numbers

You can't give us sample data and not include pertinent examples. Can you provide a better sample set (with more representative data) and demonstrate how you want it to sort?
 
You can't give us sample data and not include pertinent examples. Can you provide a better sample set (with more representative data) and demonstrate how you want it to sort?

Ditto.
 
I want to arrange numbers inside the text field (numbers from small to large)
 
With your current example (no letters and numbers mixed) you could try
Code:
Private Sub ASC_Click()
    Me.OrderBy = "val([number]) ASC"
    Me.OrderByOn = True

End Sub

Private Sub Desc_Click()
     Me.OrderBy = "val([number]) Desc"
    Me.OrderByOn = True

End Sub
As said this could get much more complicated with a mix of letters and numbers.
 
Me.RecordSource = "SELECT tabl1.number, * FROM tabl1 ORDER BY IIf([number] Is Null,0,Val([number])) ASC;"
 
مع مثالك الحالي (لا توجد أحرف وأرقام مختلطة) يمكنك المحاولة
[كود] Private Sub ASC_Click ()
Me.OrderBy = "val ([number]) ASC"
Me.OrderByOn = صحيح

End Sub

تفاصيل فرعية خاصة ()
Me.OrderBy = "val ([العدد]) تنازلي"
Me.OrderByOn = صحيح

End Sub [/ CODE]
كما قيل ، قد يصبح الأمر أكثر تعقيدًا مع مزيج من الأحرف والأرقام.
This is what is required sir... Thank you
 
Please tell us why you don't want to use a query since that is what every one of us would suggest because your data is in a recordset and queries are how you deal with recordsets. Think about what an in memory process using arrays would entail. Then think about how it would be displayed since it can't be displayed using the rows of the form. Start by looking up Bubble sort which is probably the simplest version of in memory sorting.

VBA — Bubble Sort. A bubble sort is a technique to order… | by breakCorporate | Medium
 
Please tell us why you don't want to use a query since that is what every one of us would suggest because your data is in a recordset and queries are how you deal with recordsets. Think about what an in memory process using arrays would entail. Then think about how it would be displayed since it can't be displayed using the rows of the form. Start by looking up Bubble sort which is probably the simplest version of in memory sorting
Are you looking at the correct thread? The OP wanted to use the Sort by property, there is no mention or suggestions of arrays.
 
What he said was:
I want ascending: 1, 2, 3, 4, 10, 11, 101, 121, 133 without using queries
And his example showed the data in a text box.

I did forget to mention that the only way to sort this set of data is to sort on a zero filled copy of the fields. Otherwise the result ends up as1,10, 11, 101, 121, 133, 2, 3, 4 or to use the Val() function to make the values numeric.
 
in post #4 OP said

There are letters with numbers

so
Me.OrderBy = "val ([number]) ASC"

is not going to work unless all the numbers in every record are at the beginning of the value.
 
is not going to work unless all the numbers in every record are at the beginning of the value.
Yep, I think I made that overly clear in thread 9.
 
Well the thread has been marked complete with no clue as to the actual solution.
 
Well the thread has been marked complete with no clue as to the actual solution
Huh? We know exactly the solution used. In thread 11, the OP post the solution used and even explicitly says so.
 
And I do not want to change the data type to a number. There are letters with numbers
so maybe he is expecting to have letters there.
for now, with all records in string of numbers format, it will work.
what will the future holds?

mr.murad, have a consistent coding.
you also need to have a rule on what can be
entered on that field and validate all entries against your rules.
 

Users who are viewing this thread

Back
Top Bottom