I can’t see a way to do this without a third column that can be used to group on. If you add a field to the table called ColumnC, then the Sub below would populate ColumnC with the data required to make this query work
SQL for query
Code:
SELECT Min(TableName.ColumnA) AS MinDate, Max(TableName.ColumnA) AS MaxDate, TableName.ColumnB
FROM TableName
GROUP BY TableName.ColumnB, TableName.ColumnC;
Sub
Code:
Public Sub AddValueToField()
Dim Rec As DAO.Recordset
Dim strSQL As String
Dim strPrevTown As String
Dim i As Integer
strSQL = "SELECT TableName.ColumnA, TableName.ColumnB, TableName.ColumnC " & _
"FROM TableName " & _
"ORDER BY TableName.ColumnA;"
Set Rec = CurrentDb.OpenRecordset(strSQL)
With Rec
.MoveFirst
strPrevTown = .Fields("ColumnB")
Do Until .EOF
.Edit
If strPrevTown = .Fields("ColumnB") Then
.Fields("ColumnC") = i
Else
i = i + 1
.Fields("ColumnC") = i
End If
.Update
strPrevTown = .Fields("ColumnB")
.MoveNext
Loop
End With
End Sub