By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,793 Members | 1,591 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,793 IT Pros & Developers. It's quick & easy.

Can't return to original record in a form

P: 2
I have some code that works off the update event of a textbox field (which is a part of a record in a continuous form). If certain conditions are met (following the updating of the field), I want a warning message to flash up and then the cursor must flash in the textbox relating to that record.

So, if a user updates the field on the 1st record and then clicks on the 10th record (or anywhere), the warning message (if appropriate) must appear and then the cursor must move back to the 1st record textbox field.

I would have thought that this would be basic to do but apparently even the most outwardly simple things in Access VB are made 10 times more difficult by the lack of adequate documentation.

I have spent the best part of 2 days trying to do this and as I have not solved it, I can say I am no closer than when I started.

I have tried used Absolute position, DoCmd FindRecord and many attempts on bookmarking. Nothing seems to work.

If anyone has a solution to this it would be much appreciated.

The following code is part of the after update event of the textbox in question. It gives me a data type mismatch when I try and use the Findnext method (see below). Am I on the right track here?

Public varID As Variant
'Declared in a module and holds the value of a unique field in the record in question.

Dim strBookmark As String
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
If Not IsEmpty(varID) Then
strBookmark = "code_no = " & varID 'code_no is a unique identifier for the record.
Debug.Print strBookmark 'All works fine, debug output="code_no = 1001" which is correct.
With rst
.FindFirst strBookmark 'Problem is here! Data type mismatch error.
If Not rst.NoMatch Then
Me.Bookmark = rst.Bookmark
End If
End With
End If
Sep 19 '08 #1
Share this Question
Share on Google+
2 Replies

P: 12
It helps to understand the order of events that occur in Access. If you type something into a text box and then click onto an object in another record, there are several events that fire before Access move the focus to the new record. BeforeUpdate then AfterUpdate then Exit then LostFocus thenthe focus moves to the new record.

You shouldn't need to worry about bookmarks if you are trapping the error in the before or after update events.

The Before Update event has a "Cancel" property that can be useful. If you don't like the data the user has entered just set Cancel = True in the BoforeUpdate procedure. You can also use the "Undo" command to erase what the user typed if you want to.
Sep 19 '08 #2

P: 2
Hi Boxtop,

My first reply to a forum post:)

I have learned how to use cancel which is great as a result of your message. However this is still not the perfect solution for me mainly because I only wanted to warn the user and not disallow the input entirely. It does meet my needs in that it takes the user back to the required field on the record.

Another problem is that I still need to find a way to do what I originally intended, i.e. using bookmarking or some other coding, because I have other areas in my database where I need to return to a previously visited record and in these instances "cancel" would be totally inappropriate.

Thanks for your help though!
Sep 22 '08 #3

Post your reply

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