When I enter in an item to search the PCID field with I am running into problems. If I enter in the first item in the record I get "good find" but if I enter in anything else I get "bad find". I get this even when I enter in good search item. Below is my code.
Option Explicit
'declare database variables
Public db As Database
Public rs As Recordset
Private Sub Cancel_Click()
'quits login and closes program
Unload LogInForm
End Sub
Private Sub Form_Load()
'open database
Set db = DBEngine.Workspaces(0).OpenDatabase(App.Path & "\tenneco.mdb")
Set rs = db.OpenRecordset("select PCID from parts", dbOpenDynaset)
rs.MoveLast
'centers login in center of screen
Me.Top = (Screen.Height - Me.Height) / 2
Me.Left = (Screen.Width - Me.Width) / 2
'starts user in login box
LogInForm.Show
OperatorID.SetFocus
End Sub
Private Sub LogIn_Click()
If rs.RecordCount > 0 Then rs.MoveLast
rs.MoveFirst
If rs.Fields("PCID").Value = LogInForm.OperatorID.Text Then
MsgBox "good find"
Else
MsgBox "bad find"
End If
End Sub
TIA
Craig
ucase converts lower case to upper case. That way "ABCD" can be matched with "abcd" (no case sensitivity). You'd remove the ucase if you needed case sensitivity.
You don't necessarily need to use the trim & ucase functions.
..FindFirst simply finds the first record matching the search parameter.
..noMatch tells you when no record is found
As was mentioned earlier by PaulHews you need to get string parameters enclosed within ' ', but not with numerics.
Another idea to make it easier to see what is happening.
Private Sub LogIn_Click()
dim sscan as string
msgbox sscan
sscan = "ucase(trim(PCID)) = '" & ucase(trim(LogInForm.Opera
rs.FindFirst sscan
If Not rs.NoMatch Then
MsgBox "good find"
Else
MsgBox "bad find"
End If
End Sub