Link to home
Create AccountLog in
VBA

VBA

--

Questions

--

Followers

Top Experts

Avatar of PeterBaileyUk
PeterBaileyUk

goto subform record in access
Go to record on subform using vba.

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

Open in new window


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.

User generated image

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of Scott McDaniel (EE MVE )Scott McDaniel (EE MVE )🇺🇸

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of PeterBaileyUkPeterBaileyUk

ASKER

I dont understand this:
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.

Avatar of Scott McDaniel (EE MVE )Scott McDaniel (EE MVE )🇺🇸

The Subform CONTROL is just a control you place on the form. You can name that Control whatever you like.

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?

I used your method all I had to do was save the pk of the record and then use your method to find it, works perfectly thank you.


Me.abiCode.SetFocus
SaveCode = Me.abiCode.text

Open in new window


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

Open in new window


Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Thank you!
VBA

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.