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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating a form with data from a table

Status
Not open for further replies.

Chaos424

MIS
Aug 19, 2004
4
US
I have two tables... Work Requests and Work Orders... They both have their respective data entry forms... my problem is that I want to pull the data into the create Work Orders form from the Work Requests table... then the user can modify the record and write it to the Work Orders table... this process is intended to turn a work request into a work order.... PLEASE HELP!!!
 
Do the tables have the same structure?

Or, at least, are the fields from work Requests that you need in work Orders named the same?

Likely, you should just be using a master table with the common data, and then using another table for the Orders. But let's start with the structure of the two tables.



Tony McGuire
 
Table - Work Request
-------
Fields
--------
Work_Request **PK AutoIncrement
Requested Date
Activity Alpha
Description Alpha
Priority " "
UPMH " "
DNMH " "
Basin Short Integer
DIST_UPMH Number
Pipe_Size Alpha
Pipe_Depth Alpha
Right_of_Way " "
LF Integer
Comments Memo
Entered_By Alpha
Date_Entered Date

The Created Work Orders table has all the fields that this table has and many are named the same (I think that if they have the same data type that doesn't matter)... but it also has a number of other fields. What I want to do is pull the appropriate fields from a record in the Work Requests table and populate the Create a Work Order form with them. The user can than modify or add informationa and save it as a record in the Created Work Orders table.
 
You say 'many are named the same'.

Does this mean, then, that not all fields that should have the same data have the same name?

Are the fields at least in the same order?

If neither, then you have a lot of extra work to do.

If the order is the same, then you can do something like:

var
tcR,
tcO tcursor
arRecord array[] anytype
endvar

tco_Open(":alias:work Orders.db")
; locate the appropriate record
if not tcO.qlocate("work_request",value) then
tcO.close()
msgstop("Error","Couldn't locate work request #"+string(value))
return
endif
tcO.copytoarray(arRecord)
tcO.close()
tcR.open(":alias:work request.db")
tcR.edit()
tcR.insertrecord()
tcO.copyfromarray(arRecord)
if not tcO.unlockrecord() then
tcO.canceledit()
tcO.close()
msgstop("Error","Could not copy record")
return
endif
tcO.endedit()
tcO.close()

You can probably also just use copyrecord instead of the copytoarray and copyfromarray; I'm not sure if the field names have to match for that function though.

And the above is if the field order in both tables EXACTLY match; there can't be any fields in EITHER table between the fields that are being copied.

Tony McGuire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top