Предполагая, что оба поля содержат данные в каждой записи.
Если оба поля имеют уникальные числовые значения, рассмотрим:
SELECT Query1.Seq, Query1.F1, Query2.F2
FROM
(SELECT DCount("*","Main","F2<=" & [F2]) AS Seq, Main.F2
FROM Main ORDER BY Main.F2) AS Query2
INNER JOIN
(SELECT DCount("*","Main","F1<=" & [F1]) AS Seq, Main.F1
FROM Main ORDER BY Main.F1) AS Query1
ON Query2.Seq = Query1.Seq
ORDER BY Query1.Seq;
Для другого подхода к запросу требуются два объекта запроса:
Query1
SELECT "F1" AS Src, F1 AS Data FROM Main
UNION SELECT "F2", F2 FROM Main;
Query 2
TRANSFORM First(Query1.Data) AS FirstOfData
SELECT DCount("*","Query1","Src='" & [Src] & "' AND Data<=" & [Data]) AS Seq
FROM Query1
GROUP BY DCount("*","Query1","Src='" & [Src] & "' AND Data<=" & [Data])
PIVOT Query1.Src;
Оба решения могут работать медленно с большим набором данных.
Вот подход VBA.Создайте таблицу с именем MainSorted с 3 полями:
Seq - автономный номер
F1 - номер
F2 - номер
Sub MainSort()
Dim rsSrc As Recordset, db As Database
Dim lngRow As Long
Set db = CurrentDb
db.Execute "DELETE FROM MainSorted"
db.Execute "INSERT INTO MainSorted(F1) SELECT F1 FROM Main ORDER BY F1"
Set rsSrc = db.OpenRecordset("SELECT F2 FROM Main ORDER BY F2")
lngRow = DMin("Seq", "MainSorted")
While Not rsSrc.EOF
db.Execute "UPDATE MainSorted SET F2=" & rsSrc!F2 & " WHERE Seq = " & lngRow
rsSrc.MoveNext
lngRow = lngRow + 1
Wend
End Sub
Или эта версия:
Sub MainSort()
Dim rsSrc1 As Recordset, rsSrc2 As Recordset, db As Database
Set db = CurrentDb
db.Execute "DELETE FROM MainSorted"
Set rsSrc1 = db.OpenRecordset("SELECT F1 FROM Main ORDER BY F1")
Set rsSrc2 = db.OpenRecordset("SELECT F2 FROM Main ORDER BY F2")
While Not rsSrc1.EOF
db.Execute "INSERT INTO MainSorted(F1,F2) VALUES(" & rsSrc1!F1 & "," & rsSrc2!F2 & ")"
rsSrc1.MoveNext
rsSrc2.MoveNext
Wend
End Sub
Учитывая комментарии @CPerkins:
Sub MainSort()
Dim rsSrc1 As Recordset, rsSrc2 As Recordset, rsDest As Recordset, db As Database
Set db = CurrentDb
db.Execute "DELETE FROM MainSorted"
Set rsSrc1 = db.OpenRecordset("SELECT F1 FROM Main ORDER BY F1")
Set rsSrc2 = db.OpenRecordset("SELECT F2 FROM Main ORDER BY F2")
Set rsDest = db.OpenRecordset("SELECT * FROM MainSorted")
While Not rsSrc1.EOF
rsDest.AddNew
rsDest!F1 = rsSrc1!F1
rsDest!F2 = rsSrc2!F2
rsDest.Update
rsSrc1.MoveNext
rsSrc2.MoveNext
Wend
End Sub