' ********************************************************************************
' Project file: MIXEM
' Merge the field names with real data
' Executed In-memory from menu Insert Data.
' ********************************************************************************

external $$fct $$workdir $$sysfiles, $$homedir $$file $$path $$advr working()
global mrgname()

main
graphics window cursor 4
$$fct = "Merging information from database into document"
working()
repaint off
error on
tools directory new-directory $$workdir
tools file erase $$homedir|"*.wmd" 'Cleans up screen merged files
tools file erase $$workdir|"*.wmd" '    "           "        "
tools file erase $$workdir|"*.tmp"        'Cleans up temp files created by RAD
tools file erase $$sysfiles|"notes\*.bak" 'Cleans up backup text note files
print merge file wp-document $$advr|"dummy.mrg"
clearerror
tools directory new-directory $$homedir
if lerror=0
	file unload
 	file load $$workdir|mrgname($$file)
end if
graphics window cursor 0
repaint on
repaint
end main


function mrgname($file)
	return left($file|repeat("_",5),5)|"000.wmd"
end function	




