A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Returning to the previous record after addnew



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2006, 04:31 AM posted to microsoft.public.access.forms
Ken Kazinski
external usenet poster
 
Posts: 5
Default Returning to the previous record after addnew

I have a button that copies the data from a number of tables and creates a
new record.

I want to go back to the original record after a requery, which re-sorts my
form.

Initally I used the current record but that did not always work:

Dim CurrentRecordNo As Long

CurrentRecordNo = Me.CurrentRecord

Call CopyTables

Me.Requery
'DoCmd.GoToRecord acDataForm, Me.Name, acGoTo, CurrentRecordNo

Next I tried using a bookmark but that did not work either:

Dim strBook As String

strBook = Me.Bookmark

Call CopyTables

Me.Requery
Me.Bookmark = strBook

Any help would be appreciated.
  #2  
Old December 28th, 2006, 05:54 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Returning to the previous record after addnew

The Bookmark is the way to go, but (as you found) it does not survive the
Requery. Therefore you need to save the primary key value, and FindFirst
after the requrey.

This kind of thing:
Dim rs As DAO.Recordset
Dim varID As Variant
varID = Me.[MyID]
'other stuff here
Me.Requery
Set rs = Me.RecordsetClone
rs.FindFirst "MyID = " & varID
If rs.NoMatch Then
MsgBox "not found"
Else
Me.Bookmark = rs.Bookmark
End If
Set rs = Nothing

If MyID is a Text field (not a Number type), you need extra quotes:
rs.FindFirst "MyID = """ & varID & """"
Explanation of the quotes:
http://allenbrowne.com/casu-17.html

An alternative approach that does not require a requery is to AddNew to the
RecordsetClone of the form.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Ken Kazinski" wrote in message
news
I have a button that copies the data from a number of tables and creates a
new record.

I want to go back to the original record after a requery, which re-sorts
my
form.

Initally I used the current record but that did not always work:

Dim CurrentRecordNo As Long

CurrentRecordNo = Me.CurrentRecord

Call CopyTables

Me.Requery
'DoCmd.GoToRecord acDataForm, Me.Name, acGoTo, CurrentRecordNo

Next I tried using a bookmark but that did not work either:

Dim strBook As String

strBook = Me.Bookmark

Call CopyTables

Me.Requery
Me.Bookmark = strBook

Any help would be appreciated.


 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:13 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.