Yes, you can.
One way, would be to make use of @SelectTreeItem, ClientLocalValue, @LoadExportSpec, and RunExportSpec. (Or, the new @SpecCommand can perform many of the spec related functions.)
Basically, the command button would contain something like:
var n as int
ClientLocalValue("RunMyExport", 1)
n = @SelectTreeItem(@Application + "!Forms!Search/Update!MyDB!MyForm")
This sets a global value locally (ClientLocalValue) that will be used as a conditional in the other form. Then, @SelectTreeItem opens the form you want to export from.
In the target form's
On Retrieve Open Spec event:
var n as int
// Resets the flag if previous run did not find any records to retrieve and left a flag set,
// because the flag normally doesn't get reset until the "On Form Entry" event.
If @ClientLocalValue("RunMyExport") = 2 then ClientLocalValue("RunMyExport", 0)
If @ClientLocalValue("RunMyExport") = 1
{
ClientLocalValue("RunMyExport", 2)
n = @LoadRetrieveSpec("Records to Export") //This can be left out if you want to export all records
n = @SelectTreeItem("Search Menu!Search Commands!Retrieve New Results (F10)")
}
In the form's
On Form Entry event:
var vRun as int
If @ClientLocalValue("RunMyExport") = 2 and @Update
{
ClientLocalValue("RunMyExport", 0)
vRun = @LoadExportSpec("Patients")
If vRun = 1
{
RunExportSpec("c:\Sesame2\Data\ExpPat.txt",";","",0,1,0,1,0,1,1,1)
}
@Exit
Stop //@Exit doesn't stop code in version 2, it lets the rest of the event execute.
}
You can remove the @Exit and Stop commands if you want to be left looking at the result set when the export is done; or you can leave them there to exit out of the form after the export is done.
There's always more you can include, but that should get you going in the right direction.