VBA
--
Questions
--
Followers
Top Experts
I have a subform and I can click the model and another form will display the records for that model. I have saved the record number of the model that works but the subform returns back to the first record.
I would like to go back to the record.
Me.[FrmTclientBatch].SetFocus
DoCmd.GoToRecord acDataForm, "me.FrmTclientBatch", acGoTo, 2
This code doesn't work, I've tried variations and it either says the form is not open or that it doesn't recognise the field.
Ive put record 2 here hardcoded but that will be a variable later.
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
YourSubformControlObject is the Subform Control on the parent form. That control may or may not be named the same as the form you're using as a subform, so be sure you get this right. This is probably the single thing that most people get wrong with code like this.
I think your code is to find the previous position, how do I save that position this way?
Currently I just saved the record number.
Depending on HOW you put a Subform on a Parent Form, Access will name it differently. For example, if you drag-drop a form onto another, Access will use the name of that form as the name of the Subform Control. If you add a Subform control from the controls menu, Access will give it a name like Subform1001.
My code locates a specific record in a recordset.
What do you need to save? If you want to save the position of something you determine what data you need to store in order to relocate that value, and store that in a variable. You could then use the FindFirst method to locate your record.
But it sounds almost like you're having troubles outside of that. Can you explain a bit more what sort of trouble you're having?
Me.abiCode.SetFocus
SaveCode = Me.abiCode.text
Dim rst As DAO.Recordset
Set rst = Forms![Form1].FrmTclientBatch.Form.RecordsetClone
rst.FindFirst "abiCode='" & SaveCode & "'"
If Not rst.NoMatch Then
Forms![Form1].FrmTclientBatch.Form.Bookmark = rst.Bookmark
Else
MsgBox ("Not found")
End If






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
VBA
--
Questions
--
Followers
Top Experts
Visual Basic for Applications (VBA) enables building user-defined functions (UDFs), automating processes and accessing Windows API and other low-level functionality through dynamic-link libraries (DLLs). VBA is closely related to Visual Basic and uses the Visual Basic Runtime Library, but it can normally only run code within a host application rather than as a standalone program. It can, however, be used to control one application from another via OLE Automation. VBA is built into most Microsoft Office applications.