I have a boolean declared as
Public blnchk As Boolean in the Declaration area of a form and Option Explicit set
On after update of a text box I have:
blnchk = True
CheckBoxData (blnchk)
If blnchk = False Then
Me.txtBox_Num = ""
Me.txtBox_Num.SetFocus
Exit Sub
Else
...
End If
CheckBoxData is
Public Sub CheckBoxData(blnchk As Boolean)
On Error GoTo Err_CheckBoxData
Dim rs As ADODB.Recordset
Dim swhere As String
If IsNull(Me.txtBox_Num.Value) Or Me.txtBox_Num = "" Then
MsgBox "Please enter a valid Box Number", , "AHP - Box Lookup"
blnchk = False
Me.txtBox_Num.SetFocus
Exit Sub
Else
Set rs = New ADODB.Recordset
Dim sql As String
rs.ActiveConnection = CurrentProject.Connection
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Source = "SELECT Boxes.Box_num " & _
"FROM Boxes " & _
"WHERE Boxes.Box_num =" & "'" & Me.txtBox_Num & "'" & _
"ORDER BY Boxes.Box_num "
rs.Open Options:=adCmdText
If rs.RecordCount = 0 Then
If rs.BOF And rs.EOF Then
MsgBox "Not a valid Box number", vbOKOnly, "Box Lookup"
blnchk = False
Exit Sub
End If
End If
End If
rs.Close
Exit_CheckBoxData:
Exit Sub
Err_CheckBoxData:
MsgBox "Please Try Again or Contact your Administrator", , "CheckBoxData"
Resume Exit_CheckBoxData
End Sub
HOWEVER, if CheckBoxData looks at the recordset and finds no data and sets blnchk to False, it returns back to the afterupdate with blnchk set to true
Please, what am I doing? Any help is appreciated? Thanks
Public blnchk As Boolean in the Declaration area of a form and Option Explicit set
On after update of a text box I have:
blnchk = True
CheckBoxData (blnchk)
If blnchk = False Then
Me.txtBox_Num = ""
Me.txtBox_Num.SetFocus
Exit Sub
Else
...
End If
CheckBoxData is
Public Sub CheckBoxData(blnchk As Boolean)
On Error GoTo Err_CheckBoxData
Dim rs As ADODB.Recordset
Dim swhere As String
If IsNull(Me.txtBox_Num.Value) Or Me.txtBox_Num = "" Then
MsgBox "Please enter a valid Box Number", , "AHP - Box Lookup"
blnchk = False
Me.txtBox_Num.SetFocus
Exit Sub
Else
Set rs = New ADODB.Recordset
Dim sql As String
rs.ActiveConnection = CurrentProject.Connection
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Source = "SELECT Boxes.Box_num " & _
"FROM Boxes " & _
"WHERE Boxes.Box_num =" & "'" & Me.txtBox_Num & "'" & _
"ORDER BY Boxes.Box_num "
rs.Open Options:=adCmdText
If rs.RecordCount = 0 Then
If rs.BOF And rs.EOF Then
MsgBox "Not a valid Box number", vbOKOnly, "Box Lookup"
blnchk = False
Exit Sub
End If
End If
End If
rs.Close
Exit_CheckBoxData:
Exit Sub
Err_CheckBoxData:
MsgBox "Please Try Again or Contact your Administrator", , "CheckBoxData"
Resume Exit_CheckBoxData
End Sub
HOWEVER, if CheckBoxData looks at the recordset and finds no data and sets blnchk to False, it returns back to the afterupdate with blnchk set to true
Please, what am I doing? Any help is appreciated? Thanks