Results 1 to 2 of 2
  1. #1
    Trainman is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2009
    Location
    Torrance, CA, USA
    Posts
    3

    How do I determine a SQL query result?


    Code:
    Private Sub FindCPU_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        Dim strSearchStr As String
     
        ' Clear Location Text Box.
        Me!Search_Location.SetFocus
        Me!Search_Location.Text = ""
     
        Me!Search_CPU.SetFocus
     
        ' Build the SQL query.
        strSearchStr = "SELECT CPUs.* FROM CPUs WHERE Name LIKE '" _
                    & Me!Search_CPU.Text & "'"
     
        ' Set the query.
        Me.RecordSource = strSearchStr
     
    End Sub
    With the code above, how can I determine the result of an SQL query? More importantly, how can I determine if zero records were found?

    Thanks in advance.

  2. #2
    dcrake's Avatar
    dcrake is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Aug 2009
    Posts
    435
    strSearchStr = "SELECT CPUs.* FROM CPUs WHERE Name LIKE '" _
    & Me!Search_CPU.Text & "'"

    For a start using a field named Name is very bad naming convention as this is an Access reserved word. At the very least you should put [] around it so that it can be interpreted as a field name.

    Secondly you do not need to use the .Text element.

    Finally to determine if there are any records you first need to do a dcount

    x = Nz(DCount("*","CPUs","Where [Name] Like *" & Me.Search_CPU & "*"),0)

    If no records exist the Nz() function will return zero otherwise x = number of records found.

    In your syntax your Like operator was acting as an equals operator as there was no wildcard mask in the string.

    David

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-01-2009, 03:39 PM
  2. Controls go blank on empty query result
    By kevdfisch in forum Programming
    Replies: 4
    Last Post: 08-25-2009, 08:07 AM
  3. Export a simple query result to an excel file
    By wop_nuno in forum Import/Export Data
    Replies: 1
    Last Post: 05-21-2009, 04:18 AM
  4. Result of Count Query not known elsewhere
    By Carole in forum Access
    Replies: 1
    Last Post: 09-07-2008, 09:39 AM
  5. Replies: 2
    Last Post: 08-04-2008, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums