469,275 Members | 1,796 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

FindFirst only working when setting breakpoint/debugging

I want to find and move to a record by giving the project number of a record (in a textfield).
When I set a breakpoint to the FindFirst-methodcall everything works fine, the record is found. If I do not set a breakpoint however, the RS.Bookmark is the same as the original Me.Bookmark, so nothing changes.
Here is my code:
Expand|Select|Wrap|Line Numbers
  1.         Dim RS As DAO.Recordset
  2.         Set RS = Me.RecordsetClone
  3.         If Not IsNull(Me![PNr_Searchfield]) Then
  4.             ' breakpoint here ?!
  5.             RS.FindFirst "[Proj]![PNr] = '" & Me![PNr_Searchfield] & "'"
  6.             If Not RS.NoMatch Then
  7.                 Me.Bookmark = RS.Bookmark
  8.             End If
  9.         End If
  10.         RS.Close
  11.         Set RS = Nothing
I hope someone can explain to me, what's going on here :)
Nov 15 '14 #1
4 1021
Stewart Ross
2,545 Expert Mod 2GB
Hard to say from what you have posted, as the search itself seems OK.

Is your search value control (Me![PNr_Searchfield]) bound or unbound (it would normally be unbound)? If it is bound to your recordsource for whatever reason you may could have a problem with calling the search routine before the record concerned has been updated and saved - I'm just guessing here as I don't know how you are calling your search routine.

You mention that when you set a breakpoint the search works as expected. One possible reason for this is that as the breakpoint takes the focus off the search form Access may be storing the record at that point, allowing the search to proceed normally once you step through your code.

You can test for whether or not the current record has been stored at a point just before you call your search by using something like this:

Expand|Select|Wrap|Line Numbers
  1. If Me.Dirty then
  2.   Me.Dirty = False
  3. End If
which forces record storage if the current record is in an unsaved ('dirty') condition. This will not function if it is called from the form's BeforeUpdate event, however - the record storage would trigger this again and lead to a lock-up condition.

As mentioned, without knowing more about how you are calling your search it is difficult to make an informed suggestion for you.

Nov 16 '14 #2
Thank you very much for your reply and suggestions.

The search value control is an unbound textbox. The search routine is called from within the PNr_Searchfield_KeyDown event handler. Could that be a problem? (I added the Dirty-testing as you suggested: everything seems ok.)

Nov 17 '14 #3
Stewart Ross
2,545 Expert Mod 2GB
Using an unbound control the test for the record being dirty is not required, as the control will not change the underlying record.

You are right to query the use of the Keydown event - it is triggered before any update to the control's value takes place. I suggest you use the control's AfterUpdate event instead.

Nov 17 '14 #4
Ok, I see. Thanks.
Now, when I use the AfterUpdate event with setting a breakpoint everything works fine, but without setting a breakpoint I get a "Runtime error 2001: You canceled the previous operation." at the line
Expand|Select|Wrap|Line Numbers
  1. Me.Bookmark = RS.Bookmark
. Well, that sounds mysterious to me :) Which operation did I cancel?

edit: ok, when I use
Expand|Select|Wrap|Line Numbers
  1. Me.Recordset.Bookmark = RS.Bookmark
: no runtime error, but same behaviour as in the first place.

btw: I am using Access 2003, SP3
Nov 17 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by jan82 | last post: by
6 posts views Thread by Morgan Packard | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.