Accessing subform data (1 Viewer)

AccessIsEggs

New member
Local time
Today, 07:47
Joined
Jul 24, 2019
Messages
9
Hello All,

I currently have a subform that is being filtered by a combo box.
I was curious if it was possible to access the subform data VIA VBA.

I've tried searching this for a few weeks and I really haven't been able to find anything; any source I did find that did "solve" a similar issue someone had was unavailable.

ie; I filter using my combo box, and then use VBA to pull the data from say column 1, row 1, etc.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:47
Joined
Oct 29, 2018
Messages
21,358
Hi. Welcome to the forum! You can use a recordset object to assign the content of the subform into a memory variable, so you can then work with the values using VBA. Here's one example:


Code:
Set rs = Me.SubformControlName.Form.Recordset
Hope it helps...
 

AccessIsEggs

New member
Local time
Today, 07:47
Joined
Jul 24, 2019
Messages
9
Thank you!

So, when it's in a recordset, how would I go about selecting certain data.

Please correct me if I'm wrong, but doesn't recordset take the entire data set into memory? Would I use something like

dim stringname as string

stringname = recordset![whatever I want to take from the recordset]?
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:47
Joined
Oct 29, 2018
Messages
21,358
Thank you!

So, when it's in a recordset, how would I go about selecting certain data.

Please correct me if I'm wrong, but doesn't recordset take the entire data set into memory? Would I use something like

dim stringname as string

stringname = recordset![whatever I want to take from the recordset]?
Hi. Yes, a recordset is like a table in memory. I typically use DAO, so my declaration might look something like this:
Code:
Dim rs As DAO.Recordset
To grab the information from the recordset, you could loop through it or use the .FindFirst method to search for a specific record.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Feb 19, 2002
Messages
42,984
What do you need from the recordset and how do you know what row you want to get it from? Processing the recordset of a form or subform is exactly like processing any other recordset. Be very careful to NOT update records in another form's recordset. You will get conflict errors.
 

AccessIsEggs

New member
Local time
Today, 07:47
Joined
Jul 24, 2019
Messages
9
I went ahead and used the recordset to iterate through my columns until I found the correct column (they're static so they shouldn't change ever), and then iterated through the rows to put the data into a string.

It's kind of a complex program that I'm creating, which I'm sure there are more efficient ways to do what I'm doing but that's here say.

Thank you both for your input.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Feb 19, 2002
Messages
42,984
Yep, there are more efficient ways of doing this. At least it works for you.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 07:47
Joined
Oct 29, 2018
Messages
21,358
I went ahead and used the recordset to iterate through my columns until I found the correct column (they're static so they shouldn't change ever), and then iterated through the rows to put the data into a string.

It's kind of a complex program that I'm creating, which I'm sure there are more efficient ways to do what I'm doing but that's here say.

Thank you both for your input.
Hi. Congratulations! Glad to hear you got it figured out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom