combo search box returns to first record if search string is empty (1 Viewer)

darksniper

Registered User.
Local time
Today, 01:40
Joined
Sep 4, 2005
Messages
108
hi,

I have the following code:

Code:
Private Sub uiFindByIDComboBox_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    rs.FindFirst "[sdutentId] = " & Str(Nz(Me![uiFindByIDComboBox], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark 'if this line is removed, the code wont work.
End Sub

What happens when I search for something, if the item is not found, at the moment I delete the text string, and click anywhere on the form, the form would always go to the first record.

I have looked around and I have been suggested to remove the last line, but when I remove it, the code doesn't update the form if the record is found.

Is there anything that I can do to resolve this issue.

Thank you!
 

boblarson

Smeghead
Local time
Today, 01:40
Joined
Jan 12, 2001
Messages
32,059
How about changing the code to this:
Code:
Private Sub uiFindByIDComboBox_AfterUpdate()
    ' Find the record that matches the control.
    Dim rs As Object
[COLOR="Red"]If Len(uiFindByIDComboBox & "") > 0 Then[/COLOR]
    Set rs = Me.Recordset.Clone
    rs.FindFirst "[sdutentId] = " & Str(Nz(Me![uiFindByIDComboBox], 0))
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark 'if this line is removed, the code wont work.
[COLOR="red"]End If [/COLOR]
End Sub
 

darksniper

Registered User.
Local time
Today, 01:40
Joined
Sep 4, 2005
Messages
108
thank you.

That code works for string searches.

For numeric searches, for some reason if the number doesnt match it would go to the first record.
 

boblarson

Smeghead
Local time
Today, 01:40
Joined
Jan 12, 2001
Messages
32,059
thank you.

That code works for string searches.

For numeric searches, for some reason if the number doesnt match it would go to the first record.

If it actually searches and doesn't find anything you should check with

If rs.NoMatch Then ...

do whatever you want if there is no match.
 

darksniper

Registered User.
Local time
Today, 01:40
Joined
Sep 4, 2005
Messages
108
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

I have just implemented no match, it works on numeric, but doesn't work on string searches.
 

boblarson

Smeghead
Local time
Today, 01:40
Joined
Jan 12, 2001
Messages
32,059
I have just implemented no match, it works on numeric, but doesn't work on string searches.
What do you mean it doesn't work on string searches. NoMatch means that there is no match. So, if it can't find a match, NoMatch should be true. So, something is not right here. Can you upload the database so we can see what's going on. I don't think we have the full picture here.
 

darksniper

Registered User.
Local time
Today, 01:40
Joined
Sep 4, 2005
Messages
108
Hi,

Here is simplified version of my database.
 

Attachments

  • Test_database_1.zip
    31.2 KB · Views: 174

darksniper

Registered User.
Local time
Today, 01:40
Joined
Sep 4, 2005
Messages
108
Are there any updates. Just wonder if you were able to open the database.

Thanks.
 

Users who are viewing this thread

Top Bottom