Do not let any software impress you!

Only let it convince your intellect.
Slider img 1
Do not look for a business paradise!

It is a waste of time.
Slider img 2
Only yourself can push you uphill.

There is no easy road to prizes.
Slider img 3
Productivity is the name of the game.

And you have to conquer it.
Slider img 4
As long as you understand it,

you will start to build your know-how.
Slider img 5
We can help with that.

We have the tools and the method.
Slider img 6

Related Table Related By Field Related Table's Record ID
0

Title : Record Relations

Toolbars

call BrowseFirst()
call delete_record()
call replace_relations()
call PrintGrid()
call CreateSheet()

Buttons

Fields



AutoScript

lib

proc Panels_Start()

   f = TopForm()

   t = TCreateClientStart(f)
   call TAddFld(t;"REC_ID",1,255)
   call TAddFld(t;"TBL",1,100)
   call TAddFld(t;"FLD",1,100)
   call TAddFld(t;"TBL_DESCR",1,100)
   call TAddFld(t;"FLD_DESCR",1,100)
   call TAddFld(t;"FLD_NAME";1;100)
   call TAddFld(t;"FLD_VALUE";1;100)
   call TAddFld(t;"EDITING_FORM";1;30)
   call TAddFld(t,"SYSTBL",6)
   call TCreateClientEnd(t)
   
   call AskForRelatedRecords(t,__params[4],__params[5])

   call TSetName(t;"DATA")   
end

proc Form_Start()

   call DisableLocators()

   call SetFixedCols(1)

   capt = strcat("Record Relations for (",__params[4]," : ",__params[5],")")
   call SetCaption(capt)

end

proc Form_Resize()

   call SetFixedCols(1)

end

{=============================== Lst_DblClick ================================}

proc Lst_DblClick()

     systbl = TGetFld(t,"SYSTBL")
     tname = TGetFld(t,"TBL")
     tdescr = TGetFld(t,"TBL_DESCR")
     rec_id = TGetFld(t,"FLD_VALUE")

     eform = ""
     if (systbl = 1) then
        eform = SelectFrom("SELECT DOCFORM FROM AU_KOS21 WHERE (FILENAME='",tname,"')")
     elseif (systbl = 2) then
        eform = SelectFrom("SELECT DOCFORM FROM AU_LOC21 WHERE (FILENAME='",tname,"')")
     elseif (systbl = 0) then
        eform = SelectFrom("SELECT DOCFORM FROM AU_SYS21 WHERE (FILENAME='",tname,"')")
     endif

     if (eform <> "") then
        expr0 = strcat("WORK.",tname)
        expr1 = strcat(rec_id,"=",tname)
        call OpenFormTop("ptEdit",eform,expr0,1,expr1)
     else
        call message("Undefined Form in Table ",tdescr)
     endif

end

{============================= delete_record =================================}

proc delete_record()

     rcount = TRecordCount(t)
     if (rcount > 0) then
        nl = Escape(13,10,-1)
        call message("Cannot Delete Record!",nl,"There Are (",rcount,") Relations with other Tables!")
        return
     endif
     
     {.............delete the record..............}
     
     flag = message_yes_no("Proceed with Deletion?")
     if (flag = 1) then

        call ExecuteSQL("DELETE FROM [",__params[4],"] WHERE ([",__params[6],"]=",__params[5],")")

     endif
end

{========================== replace_relations ========================}

proc replace_relations()

     {.............replace the record in relations.............}
     new_rec_id = Input("INPUT","GIVE REPLACEMENT ID",__params[5])

     flag = message_yes_no("Proceed with Record Replacement?")
     if (flag = 1) then

        rcount = TRecordCount(t)
        call TFirst(t)
        for i = 1 to rcount
        
         tname = TGetFld(t,"TBL")
         fkname = TGetFld(t,"FLD")
         ufname = TGetFld(t,"FLD_NAME")
         ufval = TGetFld(t,"FLD_VALUE")
         sql = strcat("UPDATE [",tname,"] SET [",tname,"].[",fkname,"] = ",new_rec_id," WHERE ([",tname,"].[",ufname,"]=",ufval,")")
         call ExecuteSQL(sql)

         call TNext(t)
        next

     endif
end