Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Table selection upon a form 1

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I think this is quite a tricky one but I'm not to sure.

I have numerous tables with names like 803402, 808112, 828002 etc.... All of these tables have the same structures and only differ by the information held in them.

I also have a form with a default table upon it (called 666666). This table has the same structure as those above.

I want to be able to open the form and chose the table that shows up on the form. i.e. I enter 803402 and table 803402 is open on the form where table 666666. This is a similar concept to opening the form using another table but I want to automate it.

Has anyone got any ideas?

Thanks,

Woody.
 
Woody,

This process is very similar to the one use to open reports using results from Answer tables. Here's some sample code:

Code:
var
   foi   FormOpenInfo
   frm   Form   
   str   String
endVar

   if fldTablename.Value = "" then
      msgStop( "Can't Open Table", "Reason: You need to " + 
               "type a table name." )
   else
      str = fldTableName.Value
      if not isTable( str ) then
         msgStop( "Can't Open Table", "Reason: " + str + 
                  " is not a valid table." )
      else
         foi.Name = ":WORK:FORMNAME"
         foi.MasterTable = str
         if not frm.open( foi ) then
            errorShow( "Can't View" + str",
                       "Reason: Click [>>] for details." )
         endIf
         frm.DesignModified = FALSE;
      endIf
   endIf

It's off the top of my head, so you might have to fix a couple of types or something, but it shows the basic idea.

It works by using a FormOpenInfo variable to open a form with a different master table in the data model, much the same way you can change a form's table from the Open dialog.

Setting DesignModified to FALSE prevents Paradox from prompting you to save the form after it's been changed.

Also, fldTableName refers to a field object on your form.

You'll notice I added some error checking. If you defined fldTableName as a drop-down list, you could get a list of the tables in work and then populate the drop down with the names of the tables. (See for examples and details.)

Hope this helps...

-- Lance
 
Lance, Tony or one of the other gurus probably has a more elegant solution, but I did something like this once upon a time. If I remember, it involved checking the datamodel of the form for the current table I wanted to work with, and adding it if it wasn't there. Then I reassigned the tablename value of the MRO to reflect the current table name. I don't have the code handy, but it went something like this. You may have to play with where it goes, mine was on the arrive method of the page containing the MRO (I think):

Code:
var
 curTable   string
endvar

;get your table name somehow
curTable = "MyTable.db"

if not dmHasTable(CurTable)
	then dmAddTable(CurTable)
endif

myMro.tableName = curTable
Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Mac,

There's a problem with the data model methods in this case. Unless you've given the table a specific table alias in the data model, Paradox will likely "unbind" your field objects when you rebind the tableframe/MRO. This also tends to nuke any code on the rebound objects. (Older versions of Paradox are more notorious about this than newer ones.)

In cases where the various tables have the same structure, FormOpenInfo is the better solution.

Hope this helps...

-- Lance
 
Lance, I think I remember something about that now. I dug up my old code and found that I'd done the tablename value change on individual fields, not on the an MRO. But the application (a scheduling program) works and has been working for several years now with no trouble.
Mac :)

"There are only 10 kinds of people in this world... those who understand binary and those who don't"

langley_mckelvy@cd4.co.harris.tx.us
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top