Can anyone help with this loop query? I am trying to validate an ID using recordset, here's the plan: If ID correct a message is displayed and focus advanced to next txtbox. If ID incorrect a message displays "incorrect" message AND the txtbox focus is moved back to a previous txtbox!
In the below code HOWEVER; If the ID is correct the loop skips straight through to the else statement regardless of whether the if statement is correct or not. Can anyone help with the coding??
Dim rs As DAO.Recordset ' requires DAO reference Set rs = CurrentDb.OpenRecordset("PrimaryData")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
If rs("field1") = Me.[Primary_PID] Then
MsgBox rs(0)' display correct ID
[Primary_Eye_right].SetFocus' move txtbox focus
Else
MsgBox ("incorrect")'incorrect ID
[Primary_grading_date].SetFocus 'reset focus
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
thanks
Simon
In the below code HOWEVER; If the ID is correct the loop skips straight through to the else statement regardless of whether the if statement is correct or not. Can anyone help with the coding??
Dim rs As DAO.Recordset ' requires DAO reference Set rs = CurrentDb.OpenRecordset("PrimaryData")
rs.MoveLast
rs.MoveFirst
Do While Not rs.EOF
If rs("field1") = Me.[Primary_PID] Then
MsgBox rs(0)' display correct ID
[Primary_Eye_right].SetFocus' move txtbox focus
Else
MsgBox ("incorrect")'incorrect ID
[Primary_grading_date].SetFocus 'reset focus
End If
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
thanks
Simon