Solved

finding item

Posted on 2000-05-15
8
175 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:csindorf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2810829

                    Private Sub LogIn_Click()
                     
                       
                        rs.FindFirst "PCID = " &  LogInForm.OperatorID.Text
                         
                        If not rs.NoMatch Then
                            MsgBox "good find"
                        Else
                            MsgBox "bad find"
                        End If
                                     
                    End Sub
0
 

Author Comment

by:csindorf
ID: 2811083
Adjusted points from 50 to 60
0
 

Author Comment

by:csindorf
ID: 2811084
I get "Data type mismatch in criteria expression"

Here is the code as you suggested:
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")
    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()

    rs.FindFirst "PCID = " & LogInForm.OperatorID.Text
                         
    If Not rs.NoMatch Then
        MsgBox "good find"
    Else
        MsgBox "bad find"
    End If
       
End Sub
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 38

Expert Comment

by:PaulHews
ID: 2811126
Deighton's answer is correct, but if the PCID field is a string, you will need:
 rs.FindFirst "PCID = '" & LogInForm.OperatorID.Text & "'"

String values in query criteria have to have single or double quotes around them.
0
 

Author Comment

by:csindorf
ID: 2811127
But if I enter in PCID which is the column name it come back ok, but if I enter in a value in that column no good.

TIA

Craig
0
 
LVL 18

Expert Comment

by:deighton
ID: 2811172
Private Sub LogIn_Click()

                        rs.FindFirst "ucase(trim(PCID)) = '" & ucase(trim(LogInForm.OperatorID.Text))  & "'"
                                               
                        If Not rs.NoMatch Then
                            MsgBox "good find"
                        Else
                            MsgBox "bad find"
                        End If
                             
                    End Sub
0
 

Author Comment

by:csindorf
ID: 2811241
That was it deighton!  Great.  could you please explain the line: rs.FindFirst "ucase(trim(PCID)) = '" & ucase(trim(LogInForm.OperatorID.Text))  & "'"

that way I can understand better what the code is doing.

Craig    
                       
0
 
LVL 18

Accepted Solution

by:
deighton earned 60 total points
ID: 2813561
When comparing strings "ABCD" can be different from "ABCD ".  Trim removes any leading or trailing or leading spaces to give you a nice clean string.  

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.OperatorID.Text))  &    "'"

  rs.FindFirst sscan
                                                                   
                                      If Not rs.NoMatch Then
                                              MsgBox "good find"
                                        Else
                                             MsgBox "bad find"
                                         End If
                                                 
                                        End Sub
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question