Using a specific record in a subform in VBA (For export)

jobdone

Registered User.
Local time
Today, 05:56
Joined
May 9, 2013
Messages
17
Hey everyone.

I'm kinda new to VBA so please excuse me if anything is super dumb or impossible :p

So I'm making a database for a part of the company who need a better way to hold all their info (You don't want to know how they were recording it before).

It's all been simple enough, but now I want to do something a bit fancy and I'm stumping myself.

I know how to export to Excel using preset query or table, but I want to be able to export the specific record the user has selected in a subform. The function to export is currently in a standard module. Don't know if this affects anything.

So I've kinda brain stormed a couple of ideas, but don't want to start implementing things if they're wrong.

1. Change the query to ask for the appropriate ID and run it before the export
2. Move the export code to the on-click event for the button in the subform
3. Give up and let them do it manually

The real thing I wanted to know is what's the code when I'm referring to a specific record in a subform. MainForm.SubForm.Current or something?

Thanks for any help,
Joe.
 
Assuming the record you want to export has a unique primary key, create a query and use that as criteria.

Select .....
From ....
Where somefield = Forms!yourform!yoursubform.Form!yourID;

Then use TransferSpreadsheet to export this query.
 

Users who are viewing this thread

Back
Top Bottom