Hi,
I need some help with my code.
The following was copied from my screen when I opened the table directly
ID_fk PC ClientType
1 A REP
1 C
1 C
1 C
1 C
1 C
1 C
1 C
2 A REP
2 C
2 C
2 C
2 C
2 C
4 A REP
11 A REP
11 C
13 A REP
13 C
14 A REP
18 A REP
19 A REP
19 C
19 C
19 C
19 C
++++++++++++++++++++++++++++++++++++++
My code
Private Sub cmdLoop_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim rs As DAO.Recordset
strSQL = "UniqueCustomersWithPickups"
Set rs = CurrentDb.OpenRecordset(strSQL)
'This line of code instantiates the recordset object!!!
'In English, this means that we have opened up a recordset
'and can access its values using the rs variable.
With rs
If Not .BOF And Not .EOF Then
'We don’t know if the recordset has any records,
'so we use this line of code to check. If there are no records
'we won’t execute any code in the if..end if statement.
.MoveLast
.MoveFirst
'It is not necessary to move to the last record and then back
'to the first one but it is good practice to do so.
While (Not .EOF)
'With this code, we are using a while loop to loop
'through the records. If we reach the end of the recordset, .EOF
'will return true and we will exit the while loop.
Debug.Print rs.Fields("ID_fk") & " " & rs.Fields("PC")
'prints info from fields to the immediate window
.MoveNext
'We need to ensure that we use .MoveNext,
'otherwise we will be stuck in a loop forever…
'(or at least until you press CTRL+Break)
Wend
End If
.Close
'Make sure you close the recordset...
End With
ExitSub:
Set rs = Nothing
'..and set it to nothing
Exit Sub
ErrorHandler:
Resume ExitSub
End Sub
+++++++++++++++++++++++++++++++
My results:
1 C
1 C
2 C
2 C
2 C
2 C
2 C
11 C
13 C
19 C
19 C
19 C
19 C
26 C
27 C
27 C
31 C
31 C
32 C
36 C
38 C
40 C
40 C
40 C
42 C
42 C
49 C
51 C
51 C
51 C
51 C
63 C
63 C
63 C
63 C
65 C
65 C
My question is : why am I missing all records with A in field PC and why do I picks up C only? Why is it not picking up all records? It missed all records with A in the field.
help will be appreciated. Thanks
I need some help with my code.
The following was copied from my screen when I opened the table directly
ID_fk PC ClientType
1 A REP
1 C
1 C
1 C
1 C
1 C
1 C
1 C
2 A REP
2 C
2 C
2 C
2 C
2 C
4 A REP
11 A REP
11 C
13 A REP
13 C
14 A REP
18 A REP
19 A REP
19 C
19 C
19 C
19 C
++++++++++++++++++++++++++++++++++++++
My code
Private Sub cmdLoop_Click()
On Error GoTo ErrorHandler
Dim strSQL As String
Dim rs As DAO.Recordset
strSQL = "UniqueCustomersWithPickups"
Set rs = CurrentDb.OpenRecordset(strSQL)
'This line of code instantiates the recordset object!!!
'In English, this means that we have opened up a recordset
'and can access its values using the rs variable.
With rs
If Not .BOF And Not .EOF Then
'We don’t know if the recordset has any records,
'so we use this line of code to check. If there are no records
'we won’t execute any code in the if..end if statement.
.MoveLast
.MoveFirst
'It is not necessary to move to the last record and then back
'to the first one but it is good practice to do so.
While (Not .EOF)
'With this code, we are using a while loop to loop
'through the records. If we reach the end of the recordset, .EOF
'will return true and we will exit the while loop.
Debug.Print rs.Fields("ID_fk") & " " & rs.Fields("PC")
'prints info from fields to the immediate window
.MoveNext
'We need to ensure that we use .MoveNext,
'otherwise we will be stuck in a loop forever…
'(or at least until you press CTRL+Break)
Wend
End If
.Close
'Make sure you close the recordset...
End With
ExitSub:
Set rs = Nothing
'..and set it to nothing
Exit Sub
ErrorHandler:
Resume ExitSub
End Sub
+++++++++++++++++++++++++++++++
My results:
1 C
1 C
2 C
2 C
2 C
2 C
2 C
11 C
13 C
19 C
19 C
19 C
19 C
26 C
27 C
27 C
31 C
31 C
32 C
36 C
38 C
40 C
40 C
40 C
42 C
42 C
49 C
51 C
51 C
51 C
51 C
63 C
63 C
63 C
63 C
65 C
65 C
My question is : why am I missing all records with A in field PC and why do I picks up C only? Why is it not picking up all records? It missed all records with A in the field.
help will be appreciated. Thanks