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. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|