Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24

    rs.NoMatch doenst seem to work on string searches.

    Hi,



    I have the following code which should return "No entry found" if there was nothing found. But instead I am getting default ms access error message.

    Although the code works on numeric searches, it just doesn't want to work on string searches.

    Is there anything I can or check to find out why it doesn't work.

    Code:
    Private Sub Combo96_AfterUpdate()
        ' Find the record that matches the control.
        Dim rs As Object
     If Len(Combo96 & "") > 0 Then
        Set rs = Me.Recordset.Clone
        rs.FindFirst "[sdutentId] = " & Str(Nz(Me![Combo96], 0))
        If rs.NoMatch Then
            MsgBox "No entry found"
        Else
            Me.Bookmark = rs.Bookmark
        End If
        Set rs = Nothing
        DoCmd.GoToControl "Combo96"
        End If
    End Sub

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Strings need to be enclosed in quotes. Try:
    rs.FindFirst "[sdutentId] = '" & Nz(Me![Combo96], 0) & "'"

  3. #3
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    I have just tried it, still there is no change.

    If you want I can post a copy of the database, if that is going to make it easier.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Sure, go ahead and post the zipped up db.

  5. #5
    MAF4Fam6's Avatar
    MAF4Fam6 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Dec 2009
    Location
    Fruit Heights, Utah USA
    Posts
    140

    Post rs.NoMatch doenst seem to work on string searches.

    Is it possible the sdutentID field name is misspelled which may be causing the problem? Should it read: StudentID ?

    -RC

  6. #6
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    sdutentID, is the actuall spelling, I misspelled it when I have created the table, too late to change it now.

    If record exists -> the code finds it and displays it.
    If record does not exist -> I get default ms access error which I want to get rid off.

  7. #7
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    Here is the database.

    Sorry for double post, didn't find attach option in edit section.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    OK, so your find is now working. I do not know what error you are getting but why are you trying to go to "Combo96" in the AfterUpdate event of that very control? That will not work.

  9. #9
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    After-update code was partially generated by access.

    Combo96 searching always worked, it just gave a weird error when it could not find the search string.

    What I wanted to do, is to change the weird error that ms access generates, and provide something more useful.

    That's why I have modified combo96, to catch all of the issues. Except that noMatch doesnt seem to work.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You have it set to LimitToList, right? Are you aware that Recordset.Clone is a method of an ADO Recordset and RecordsetClone is a property of a DAO Recordset and NoMatch is DAO? You should not really mix them.

  11. #11
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    Nope, I wasnt aware of that, how can I implement limit to list to fix the issue.

    Thank you!

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You *DO* have it set to YES and it is a property on the Data tab of the control. What error are you trying to intercept?

  13. #13
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    Hi,

    LimitToList was already set to Yes.

    Error:
    "The text you have entered isn't an item in the list" that the default msaccess error that I want to change.

  14. #14
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows XP Access 2002
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Now we are getting somewhere! That is the error you get when you type something into the ComboBox and LimitToList is set to YES. You will need to change your bound column if you want to set that property to NO.

  15. #15
    darksniperx is offline Novice
    Windows 7 Access 2003
    Join Date
    Dec 2009
    Posts
    24
    As soon as I change bound column to any other number than 1, ms access crashes.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. VBA Code To Work With MySQL
    By botts121 in forum Programming
    Replies: 0
    Last Post: 07-08-2009, 08:51 AM
  2. Replies: 0
    Last Post: 02-27-2009, 01:39 PM
  3. Forms don't work the same
    By hawzmolly in forum Access
    Replies: 0
    Last Post: 12-18-2008, 05:46 PM
  4. Can't get TransferSpreadsheet to work
    By Valeda in forum Import/Export Data
    Replies: 0
    Last Post: 07-19-2007, 08:04 AM
  5. Nested IIf query will not work
    By ddog171 in forum Queries
    Replies: 1
    Last Post: 06-20-2006, 02:03 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