Home

DoCmd.ShowAllRecords

%3CLINGO-SUB%20id%3D%22lingo-sub-1244399%22%20slang%3D%22en-US%22%3EDoCmd.ShowAllRecords%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1244399%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20created%20an%20app%20which%20opens%20a%20form%20listing%20all%20entries.%20It%20has%20an%20open%20text%20box%20which%20opens%20another%20form%20with%20the%20selected%20record%20(or%20new).%20After%20updating%20the%20info%2C%20the%20save%20command%20button%20closes%20the%20form.%20My%20issue%20is...how%20do%20I%20return%20to%20the%20record%20that%20was%20updated%20(added)%3F%20In%20development%2C%20I%20found%20%22%3CFONT%3EDoCmd.ShowAllRecords%22%3C%2FFONT%3E%20as%20the%20only%20way%20to%20reflect%20the%20update%20on%20the%20first%20form.%20But%2C%20it%20repositions%20to%20the%20beginning%20(top)%20of%20the%20database.%20Is%20there%20some%20other%20option%20to%20update%20the%20first%20form%20and%20remain%20on%20the%20updated%20record%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1244399%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAccess%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
Occasional Visitor

I have created an app which opens a form listing all entries. It has an open text box which opens another form with the selected record (or new). After updating the info, the save command button closes the form. My issue is...how do I return to the record that was updated (added)? In development, I found "DoCmd.ShowAllRecords" as the only way to reflect the update on the first form. But, it repositions to the beginning (top) of the database. Is there some other option to update the first form and remain on the updated record?

1 Reply
Highlighted

@RichardHG There are two questions here, actually.

 

First, there's the issue of requerying the original, calling form after adding a new record to a second form which you open for that purpose.

 

Since you don't show us how you actually open that second form for input, I'm going to make a bit of a guess. Something like this?


DoCmd.OpenForm formName:="frmYourFormNameGoesHere", view:=acNormal, datamode:=acFormEdit, windowmode:=acWindowNormal

 

If so, then you can take advantage of the fact that opening a popup form, in dialog mode, suspends that VBA procedure until the popup is closed again. Like this.

 

DoCmd.OpenForm formName:="frmYourFormNameGoesHere", view:=acNormal, datamode:=acFormEdit, windowmode:=acDialog
Me.Requery

 

When you do that, the Me.Requery line fires after you have made your edit or update in the other form, which has the same effect as your current approach.

 

That leaves the problem of returning to the same record after the Requery.

 

To do that you'll need to identify the current record BEFORE opening the popup for edit.

 

Set a variable to the value of the current record's primary key.

 

Dim lngYourRecordPrimaryKey  As Long

Set lngYourRecordPrimaryKey = Me.PrimaryKeyfortheCurrentRecordGoesHere

 

then the two lines to open the popup and requery the calling form.

 

And finally, move focus to the record matching the variable, lngYourRecordPrimaryKey .