Some subtle changes, but you will need to modify the dcount, to make sure
that the table and fields being checked, are correct... This option assumes,
that the Cass ID is stored in a table;
Private Sub btnSearch_Click()
Dim message, title, myvalue
message = "Please Enter The Cass/DVD ID"
title = "Mike's Video Rental"
myvalue = InputBox(message, title)
'if user clicks on cancel...
If Len(myvalue) = 0 Then Exit Sub
'If there is a CassID in the table, then this is a valid id...
If DCount("[CassID]","table name","[CassID]='" & myvalue & "'") > 0 Then
Me.lblRentalList.Value = myvalue
Else
MsgBox "Not a valid Cass ID"
End If
End Sub
Alternatively, you could iterate through your list box, to see if the value
entered is valid or not, instead of doing a dcount (the following example,
assumes your list box is called listListBox). NOTE: if you use this example,
you will need to ensure, that the bound column property, of your list box,
is the same column number, that your Cass ID is stored in. You have said,
that the list box contains 6 columns, so the bound column (which is the
ItemData property of the list box), must be the column number that the Cass
ID is in;
Private Sub btnSearch_Click()
Dim message, title, myvalue
message = "Please Enter The Cass/DVD ID"
title = "Mike's Video Rental"
Dim myLoop As Long
Dim blnFound As Boolean : blnFound = False
myvalue = InputBox(message, title)
'if user clicks on cancel...
If Len(myvalue) = 0 Then Exit Sub
'If there is a CassID in the list box, then this is a valid id...
For myLoop = 1 To listListBox.ListCount
If listListBox.ItemData(myLoop) = myvalue Then
blnFound = True
Exit For
End If
Next
If blnFound Then
Me.lblRentalList.Value = myvalue
Else
MsgBox "Not a valid Cass ID"
End If
End Sub
learningMikey said:
Ok..I found my solution but partial. Below is the code
Private Sub btnSearch_Click()
Dim message, title, myvalue
message = "Please Enter The Cass/DVD ID"
title = "Mike's Video Rental"
myvalue = InputBox(message, title)
Me.lblRentalList.Value = myvalue
End Sub
Now what I am looking for is lets say user by mistake enters something that
is not in the list box. Then I want system to display the message stating
invalid. How do I detect it is invalid? I am not getting this part.
Thanks.