I try to find a record in a table (tbl_labels), when a record in the table has the same value as the textbox "ID-Code" in a form. Target is to make a toggle that turn cmdButtons on and off. The toggle does not work. Can someone help me out ? I guess the problem of not toggling the .noMatch statement, is caused by the statement FindFirst.
ID-Code on the form is a numeric field, from table "Codes".
"Tag" is the name of the field in the table called "tbl_labels"
Thanks in advance for your help.
Please find the script below:
Private Sub Form_Current()
Dim db As Database
Dim rs As Recordset
Dim Number As String
Dim strCriteria As String
Dim Green As Long, Cyan As Long, Red As Long, Yellow As Long, Orange As Long
Number = 0
Number = Me.ID_CODE
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl_labels", dbOpenSnapshot)
''RGB Color codes taken from http://gucky.uni-muenster.de/cgi-bin/rgbtab-en
Green = RGB(0, 255, 0)
Cyan = RGB(0, 255, 255)
Red = RGB(255, 0, 0)
Yellow = RGB(255, 255, 0)
Orange = RGB(255, 165, 0)
If Me.Label_required = True Then
With rs
.MoveFirst
.FindFirst "str([tag])=' Number'"
''MsgBox "Record(s) to search has ID-CODE " & Number
''If not found, property of NoMatch is "True"
If .NoMatch Then
''MsgBox ("No Records Found!")
''here comes action
Me.Knop100.Enabled = False
.MoveFirst
Else
''MsgBox "Record(s) found ; ID-CODE of found label is " & Number
''here comes action
Me.Knop100.Enabled = True
End If
End With
End If
Set rs = Nothing
Set db = Nothing
End Sub