Hi I'm a VB newbie and was wondering if someone might be able to help me with a looping problem. I am trying to adapt an if/ else statement to include a counting loop which if condition not met I want programme to update an errorlog table with txtbox data. here's the spec: -
'User inputs PID, presses TAB and afterUpdate()searches table tbl_Abbot_PID for PID.
'if correct PID message box displays PID, curser moves to eye txtbox.
'if incorrect PID message displays incorrect PID and moves curser back to previous txtbox. I wish to add an expression or loop to limit the number of attempts the user has to insert correct ID to twice. If PID incorrect the second time around I then need to insert txtbox PID data into tbl_errorlog and move focus to eyetext box and keep going
Private Sub Photoset_PID_AfterUpdate()
Dim CkSt As Integer
Dim strmsg As Variant
Dim RGCarrivalDate As Date
Dim cn As ADODB.Connection
Dim rs As DAO.Recordset ' requires DAO reference
'assumes number data type for Abbot_PID
Set rs = CurrentDb.OpenRecordset( _
"Select * From tbl_Abbot_PID " & _
"Where Abbot_PID =" & Me.[Photoset_PID])
If rs.EOF And rs.BOF Then
'I think i need to add a counting loop here???
'For k = 0 To 1
CkSt = 0
strmsg = "incorrect PID"
' move focus back to previous text box
Me.[txtDateVisible].SetFocus
'Next
Else
CkSt = 1
strmsg = rs.Fields(0)
End If
MsgBox strmsg
If CkSt = 1 Then
Me.[txtEye].SetFocus
RGCarrivalDate = rs.Fields(1)
Me.txt_RGC_arrival_date = rs.Fields(1)
Else
Me.[txtDateVisible].SetFocus
Dim cn As ADODB.Connection
cn.Open "provider= microsoft.jet.oledb.4.0;" & "data source=" & "D:\Swk\Photoset PTB Project\Photoset_PTB_1.1.mdb
cn.Execute "INSERT INTO tbl_Errorlog " & "(Abbot_PID) VALUES (" & Me.txt_testbox & ");"
Me.[txtEye].SetFocus 'reset
End If
rs.Close
cn.Close
Set rs = Nothing
End Sub
thanks.
'User inputs PID, presses TAB and afterUpdate()searches table tbl_Abbot_PID for PID.
'if correct PID message box displays PID, curser moves to eye txtbox.
'if incorrect PID message displays incorrect PID and moves curser back to previous txtbox. I wish to add an expression or loop to limit the number of attempts the user has to insert correct ID to twice. If PID incorrect the second time around I then need to insert txtbox PID data into tbl_errorlog and move focus to eyetext box and keep going
Private Sub Photoset_PID_AfterUpdate()
Dim CkSt As Integer
Dim strmsg As Variant
Dim RGCarrivalDate As Date
Dim cn As ADODB.Connection
Dim rs As DAO.Recordset ' requires DAO reference
'assumes number data type for Abbot_PID
Set rs = CurrentDb.OpenRecordset( _
"Select * From tbl_Abbot_PID " & _
"Where Abbot_PID =" & Me.[Photoset_PID])
If rs.EOF And rs.BOF Then
'I think i need to add a counting loop here???
'For k = 0 To 1
CkSt = 0
strmsg = "incorrect PID"
' move focus back to previous text box
Me.[txtDateVisible].SetFocus
'Next
Else
CkSt = 1
strmsg = rs.Fields(0)
End If
MsgBox strmsg
If CkSt = 1 Then
Me.[txtEye].SetFocus
RGCarrivalDate = rs.Fields(1)
Me.txt_RGC_arrival_date = rs.Fields(1)
Else
Me.[txtDateVisible].SetFocus
Dim cn As ADODB.Connection
cn.Open "provider= microsoft.jet.oledb.4.0;" & "data source=" & "D:\Swk\Photoset PTB Project\Photoset_PTB_1.1.mdb
cn.Execute "INSERT INTO tbl_Errorlog " & "(Abbot_PID) VALUES (" & Me.txt_testbox & ");"
Me.[txtEye].SetFocus 'reset
End If
rs.Close
cn.Close
Set rs = Nothing
End Sub
thanks.