Dave,
You mentioned 15 postcodes. You also mention "The target for me is in the recordset is to find out if postcode is > 1", and also "grouped to count how many branches with different postcodes".
I am not familiar with UK postcodes, but I think you are referring to incodes based on this diagram.

I have modified my test data as follows
recid |
PostCode |
shipmentDate |
delTo |
1 |
abc |
2025-08-03 |
Dave here |
2 |
abc |
2025-08-03 |
Dave here |
3 |
abc |
2025-08-03 |
Dave here |
4 |
abc |
2025-08-03 |
Dave there |
5 |
def |
2025-08-03 |
Dave there |
6 |
def |
2025-08-03 |
Dave there |
7 |
ghi |
2025-08-03 |
Dave somewhere |
8 |
abc |
2025-08-03 |
Dave here |
9 |
abc |
2025-08-03 |
Dave here |
10 |
abc |
2025-08-03 |
Dave here |
11 |
def |
2025-08-03 |
Dave there |
12 |
def |
2025-08-03 |
Dave there |
14 |
ghi |
2025-08-03 |
Dave somewhere |
15 |
ghi |
2025-08-03 |
Dave somewhere |
16 |
ghi |
2025-08-03 |
Dave somewhere |
I have no idea where your postcode >1 shows up in your SQL or code?? You hid the outcodes so I can only use my abc, def, ghi to test.
Revised sql result showing branches/incodes within postcode
Code:
branches |
PostcodeCount |
abc |
7 |
def |
4 |
ghi |
4 |
This is the sql used to get the 7 branches/incodes within postcode abc.
Code:
SELECT
tblEdit2.PostCode AS branches,
COUNT(*) AS PostcodeCount
FROM
tblEdit2
WHERE
DelTo LIKE'DAVE'& "*"
GROUPBY
tblEdit2.PostCode
My version for testing your vba code.
Code:
Sub DaveAug2025()
Dim strFullName As Variant, strFirstWord As String, strSQL As String
Dim intPCQty As Integer
Dim dtShipWeek As Date
Dim rs As DAO.Recordset
Dim i As Integer
Dim result As String
dtShipWeek = #8/3/2025# 'Forms!frmRoutes!txtShipmentDate
'strFullName = Split(Me.DelTo)
strFirstWord = "DAVE" 'Trim$(strFullName(0))
i = Len(strFirstWord)
'strSQL = "SELECT COUNT(*) AS PostcodeCount" _
& " FROM tblEdit2" _
& " WHERE ShipmentDate = #" & Format(dtShipWeek, "mm/dd/yyyy") & "#" _
& " AND DelTo Like ""*" & strFirstWord & "*"""
' Above strSQL count is 15 Correct
'Below strSQL count is 2, grouped to count how many branches with different postcodes, should be 7 in this case
strSQL = "SELECT tblEdit2.PostCode as Branches, COUNT(*) AS PostcodeCount FROM tblEdit2" _
& " WHERE DelTo LIKE 'DAVE' & '*'" _
& " Group BY tblEdit2.PostCode "
Set rs = CurrentDb.OpenRecordset(strSQL)
With rs
If Not (.BOF And .EOF) Then
.MoveFirst
End If
Debug.Print "PostCode Branches/incodes within"
Do While Not .EOF
result = !branches & " " & intPCQty + rs!PostcodeCount
Debug.Print result
rs.MoveNext
Loop
.Close
End With
Debug.Print strSQL
'Stop
End Sub
Result:
Code:
PostCode Branches/incodes within
abc 7
def 4
ghi 4
Hope this is helpful.