Results 1 to 6 of 6
  1. #1
    MBA80 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2012
    Posts
    13

    Search Record Button

    The DB i created recently (thank you to those who helped with my previous questions.) has hit a bump. The users are making mistakes when they are entering their data in the form and are asking for a "search" button to be able to look for the record(s) they may have made errors on. The problem I have is that none of the fields are required for this form other than HoursToComplete (which is the whole purpose of the DB, the rest of it is just for cosmetic info for "the boss." So I did some digging around and found this coding for my search box event


    Code:
    Private Sub Command21_Click()
    If IsNull(Search1) = False Then
            Me.Recordset.FindFirst "[BasicInfo].[YourName]=" & Search1
            Me!Search1 = Null
            If Me.Recordset.NoMatch Then
                MsgBox "No record found", vbOKOnly + vbInformation, "Sorry"
                    Me!Search1 = Null
            End If
        End If
    End Sub
    Search1 is the field in which I wanted people to be able to seach for their names they have entered when entering the data. (It is optional but I can make it required if need be.) Currently they enter their first and last name in to the same field for simplicitys sake.

    BasicInfo is the core table for the DB, and YourName is the field that records the names entered in to the form.

    I am testing this currently and it fails to return any information when I do a search. It retuns my little pop-up box that says "sorry, no record found" every time. Where have I made the mistake in the coding, or do I need to do something like splitting first and last name in to seperate fields and requiring the last name at a minumum?

    Any help would be appreciated.

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,593
    I think you will have to 'couch' your Search1 in quotation marks since it is a string.
    Try something like this:
    Code:
    "[BasicInfo].[YourName]= '" & Search1 & "'"
    
    After the = sign is a single quote - ' - and a double quote - " .
    After Search1 & is a double, a single and a double quote.

    Look here for a good set of examples:
    http://www.baldyweb.com/wherecondition.htm

  3. #3
    MBA80 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2012
    Posts
    13
    About to head home for the day, but I tried changing the syntax to what you recommended and still came back with the same results as before. The link you gave talks about having a new form open to display the results of the search. I was thinking that may be my issue as I don't see anywhere in the code to output the information I am searching for. (Being totally new to any type of coding, I may just not understand what I am looking at.) With the search still results in a "no records found" message I didn't look too much further in to that yet.

  4. #4
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Quote Originally Posted by Robeen View Post
    I think you will have to 'couch' your Search1 in quotation marks since it is a string.
    Try something like this:
    Code:
    "[BasicInfo].[YourName]= '" & Search1 & "'"
    
    After the = sign is a single quote - ' - and a double quote - " .
    After Search1 & is a double, a single and a double quote.

    Look here for a good set of examples:
    http://www.baldyweb.com/wherecondition.htm
    This is almost always the answer, something up with the quotes. I've always found using double quotes works best for the code I write. To render one in your statement you need a pair of double quotes (" ") together: ""

    So I would write like this: "[BasicInfo].[YourName]=""" & Search1 & """"

    When processed the string will look like this: [BasicInfo].[YourName]="Dre"

    You could also try to assign the value to a variable before using it to search:

    dim searchstring as string
    searchstring =
    "[BasicInfo].[YourName]=""" & Search1 & """"
    msgbox searchstring 'so that you can see the criteria string passed before it runs
    Me.Recordset.FindFirst searchstring

  5. #5
    MBA80 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2012
    Posts
    13
    A question about this again. I haven't gotten it all worked out to function properly yet, but lets say I enter my name in to the search field to look for my tickets. It should return the first record with my name in it, but then how would the user navigate through all of their records? Wouldn't I need to create a new form with buttons to allow them to move between next and last records for them to be able to go through their entries? I may be over complicating this whole thing in my head though.

  6. #6
    dreday's Avatar
    dreday is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    58
    Quote Originally Posted by MBA80 View Post
    A question about this again. I haven't gotten it all worked out to function properly yet, but lets say I enter my name in to the search field to look for my tickets. It should return the first record with my name in it, but then how would the user navigate through all of their records? Wouldn't I need to create a new form with buttons to allow them to move between next and last records for them to be able to go through their entries? I may be over complicating this whole thing in my head though.
    Sounds like you'd be much better off using a parameter query as a record source in your form. Then you can use the record selectors to move back and forth.

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

Similar Threads

  1. Replies: 12
    Last Post: 03-22-2012, 02:48 AM
  2. Replies: 10
    Last Post: 03-21-2011, 02:46 PM
  3. Search Button
    By injanib in forum Forms
    Replies: 1
    Last Post: 01-16-2011, 07:36 AM
  4. Replies: 6
    Last Post: 02-09-2010, 07:53 AM
  5. Replies: 3
    Last Post: 01-14-2010, 08:32 AM

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