Hi
I have got a search routine working in Excel, but need it in Access as the number of records is too large for Excel.
I have two tables. Table 1 has fields PCode and general data, Table 2 has fields Pcode and EXZ.
The number of Pcode in Table 2 is only exhaustive when the search routine below is used and is much less than the numbers of Pcode in Table 1. I eventually need to group the data in Table 1 by EXZ.
I have tried joining the two tables, but cannot get the procedure below to work across the join.
Below is the Excel coding that works.
I am not familiar with Access VBA syntax, like how to call a table etc. I'm going on a course soon . . .
Cheers, hope it is all clear and thanks in advance
Rich
I have got a search routine working in Excel, but need it in Access as the number of records is too large for Excel.
I have two tables. Table 1 has fields PCode and general data, Table 2 has fields Pcode and EXZ.
The number of Pcode in Table 2 is only exhaustive when the search routine below is used and is much less than the numbers of Pcode in Table 1. I eventually need to group the data in Table 1 by EXZ.
I have tried joining the two tables, but cannot get the procedure below to work across the join.
Below is the Excel coding that works.
Code:
Sub PostCode()
'Binary Search of PostCode Data
Dim PCFound As Boolean
For a = 2 To Workbooks("Post Code Development").Worksheets("Pcode A").UsedRange.Rows.Count Step 1
PC = Workbooks("Post Code Development").Worksheets("Pcode A").Cells(a, 1)
PC = UCase(PC)
PClen = Len(PC)
NumberPCs = Workbooks("PostCodeLookup").Worksheets("Post_code").UsedRange.Rows.Count - 1
PCFound = False
s = 2
f = NumberPCs
j = 0
For j = PClen To 1 Step -1
k = 0
Do While k < 15
k = k + 1
i = Round((s + f) / 2, 0)
'alpha = post code
alpha = Mid(PC, 1, j)
'beta = postcode being compared to
beta = Workbooks("PostCodeLookup").Worksheets("Post_code").Cells(i, 1).Value
If alpha > beta Then
s = i
ElseIf alpha < beta Then
f = i
Else
exitzone = Workbooks("PostCodeLookup").Worksheets("Post_code").Cells(i, 2).Value
PCFound = True
GoTo Found
End If
Loop
Next j
Found:
If PCFound = True Then
Workbooks("Post Code Development").Worksheets("Pcode A").Cells(a, 2) = exitzone
Else
Workbooks("Post Code Development").Worksheets("Pcode A").Cells(a, 2) = "---"
End If
Next a
I am not familiar with Access VBA syntax, like how to call a table etc. I'm going on a course soon . . .
Cheers, hope it is all clear and thanks in advance
Rich