Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Back to duplicating a record with child tables.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Back to duplicating a record with child tables.

    Ok, I am pulling up this back up as I finally got around to trying so of the code Tom suggested in this thread.
    http://www.alphasoftware.com/alphafo...ly-not-working

    What I am trying to do is duplicate a record that consist of one record in the parent table, multiple records in the items table and one record in the sp_art table

    I tried the code Tom suggested and it seems very slow plus it causes the tabbed object on the form to switch tabs and then flash.

    My old code is way faster and does not cause any tab changing or flashing. This code duplicates the parent record and then using a temp_db copies the records from the one to many child into it and then appends that info into the actual child table used by the set.

    The reason I even tried the code Tom posted is because I need to also duplicate a record that is in a one to one of the parent.
    Using the same method I used in my code of copy to temp and then append, I end up getting a error "Index not Open" or something like that when I try to do anything on the duplicated record in the form.

    I also tries to add to Tom's modified code to see if I could pull that child record into the a new record. No mater what I tried it always pulled the wrong data and seemed to be pulling data from the items table.

    I have also attached the code from both Tom's example that has been modified for my tables and also my older code.

    Here is a video that I hope explains it better. Please excuse the background noise but it is 102 degrees so I have a fan blowing on me.



    Here is a link to the code. The "est_dup_new" is based on what Tom posted and the "est_dup" is my code without the code to try and pull the single record from the other child table.
    http://www.shopcalmanager.com/dl/est...08-12-2016.txt

    If anyone can point me in the right direction it would be greatly appreciated.

    #2
    Re: Back to duplicating a record with child tables.

    Preston,

    Have you tried copying/duplicating the single child record BEFORE duplicating the one-to-many records?

    Comment


      #3
      Re: Back to duplicating a record with child tables.

      Originally posted by WokingJon View Post
      Preston,

      Have you tried copying/duplicating the single child record BEFORE duplicating the one-to-many records?
      Not for the one I am showing in the video and code examples but I have another one that is a parent with 5 one to one child tables and I am not having any luck with it either.

      Comment


        #4
        Re: Back to duplicating a record with child tables.

        Code:
        mm=table.current(1)   'header table
        g1=table.get("one to one table name")
        g11=table.open(g1.name_get())
        
        ''navigate to the record in the one to one table you want to duplicate
        
        g1_rec=g1.record_data_get()
        g11.enter_begin()
        g11.record_data_set(g1_rec)
        g11.key field name=[B][COLOR="#FF0000"]mm.key field[/COLOR][/B]
        g11.enter_end(.t.)
        g11.close()
        Last edited by Ronald Anusiewicz; 08-13-2016, 10:39 AM. Reason: Found error in code
        Alpha 5 Version 11
        AA Build 2999, Build 4269, Current Build
        DBF's and MySql
        Desktop, Web on the Desktop and WEB

        Ron Anusiewicz

        Comment


          #5
          Re: Back to duplicating a record with child tables.

          Thanks Ronald.

          I will look into that for the 1 to 1 child tables.

          I am reading the docs on the tbl.record_data_get and tbl.record_data_set methods right now. At least the internal docs on this has not been screwed up by Alpha removing the Wiki site.

          I know this does not work like I would want with the 1 to many child tables as it causes that screen flashing I showed in the video.

          Thanks.

          Comment


            #6
            Re: Back to duplicating a record with child tables.

            Many many ways for single records. Nothing like the blob for children
            '----------Copy Children records------------------------

            Code:
            addhd = table.open("child.dbf")          'you must open a second  copy of your child table if copying to the same child table (as you are) to add to it
            dim record_data as B					
            tbl = table.current(2)						'the child table in the browse to copy assumes here (2)	the table name of this is what you use above					
            tbl.fetch_first()                                                  'start at the first of course
            while .not. tbl.fetch_eof()
            	line_data = tbl.record_data_get()			'blob get record into record_data
            	ADDhd.enter_begin()
            	ADDhd.record_data_set(line_data)			'write duplicate child - blob set
            'change the key field to your master key....	ex. addhd.kfield = the header key
            	ADDhd.enter_end(.T.)
            	tbl.fetch_next()
            end while
            addhd.close()
            I was going to give you the reason for your code causing the flashing, but that would not have provided the total solution.
            This method totally eliminates that conflict.
            what can be simpler
            Last edited by Ray in Capetown; 08-13-2016, 01:08 PM.

            Comment


              #7
              Re: Back to duplicating a record with child tables.

              Preston,

              This script duplicates the set whose structure I've attached. This script has a lot of fluff which can easily be removed.
              There are probably a couple of errors as I already deleted quite a bit of fluff. As you can read, this script was originally written in 2004.

              Code:
              'Date Created: 12-Jan-2004 04:33:25 PM
              'Last Updated: 05-Aug-2015 09:27:07 PM
              'Created By  : Scott Emerick, KEYTECH 2000
              'Updated By  : Ron
              
              
              parentform.Commit()
              UI_Yield()
              
              tbl = table.current()
              
              'Get 'Value' property of 'Transno' in Form 'MInvoices' .
              DIM SHARED vCurTransNo AS c
              vCurTransNo = parentform:Transno.value
              
              dim msg as C
              msg = " Duplicating Selected Items to a New Invoice"
              dim shared curfile as C = ""
              PleaseWait45(.t.,msg)
              
              'strip the Item and Description from the select items, add the field = statement, trim
              'leading and trailing spaces and replace the crlf with .or.
              vMItems = *for_each(foo, word2(foo, 3, "|") ,vMItems)
              
              dim vFilter as C
              vfilter = alltrim(vMItems)
              
              pct=3	'PleaseWait Funtion
              ui_modeless_dlg_refresh(msg)
              ui_yield()
              
              dim tz as P
              tz = table.open("tmp_msquawk")
              tz.zap(.t.)
              tz.close()
              
              
              pct=6	'PleaseWait Funtion
              ui_modeless_dlg_refresh(msg)
              ui_yield()
              
              dim tbl_source as P
              dim qry as P
              tbl_source = table.open_session("msquawk",FILE_RO_SHARED)
              query.order = "Transno+swkno"
              query.filter = "Transno = var->vCurTransNo"
              qry = tbl_source.query_create()
              tbl_source.fetch_first()
              
              WHILE .not. tbl_source.fetch_eof()
              	IF word_exists(vFilter, tbl_source.swkno, crlf() ) = .T. THEN
              		result = tbl_source.copy_record_to("tmp_msquawk")
              	END IF
              	tbl_source.fetch_next()
              END WHILE
              
              qry.drop()
              tbl_source.close()
              
              pct=12	'PleaseWait Funtion
              ui_modeless_dlg_refresh(msg)
              ui_yield()
              
              'Create a new header and add the correct number of squawks
              dim mm as p
              dim mc as p
              dim tmp_t as p
              dim i as n
              dim old_mm as b
              
              tmp_t = table.open("tmp_msquawk")
              
              mm=table.current(1)			'Minv_hdr2
              mc=table.current(2)			'Msquawk
              g1=table.get("mfix")
              g2=table.get("mlabor")
              g3=table.get("mparts")
              g4=table.get("mship")
              g5=table.get("mosw")
              g6=table.get("mmisc")
              
              pct = 15
              ui_modeless_dlg_refresh(msg)
              UI_Yield()
              
              mm2=table.open(mm.name_get())
              mc2=table.open(mc.name_get())
              g11=table.open(g1.name_get())
              g22=table.open(g2.name_get())
              g33=table.open(g3.name_get())
              g44=table.open(g4.name_get())
              g55=table.open(g5.name_get())
              g66=table.open(g6.name_get())
              
              'First, the header record gets copied
              old_mm = mm.record_data_get()
              mm2.enter_begin()
              'note:  in the table the transno is an autoincrement field.  A new transno is assigned
              'by the field rule which overrides the Xbasic record_data_set()
              mm2.record_data_set(old_mm)
              LastInvNo = dbmax("minv_hdr2","SiteOnly",var->vcLocation,"Inv_No")
              newInvNo = "M" + ( padl(alltrim(str(val(right(LastInvNo,6) ) + 1)),6,"0")   )
              mm2.inv_no = newInvNo
              mm2.SJINV_NO = ""
              mm2.PAID = "N"
              mm2.qb_post = ""
              '''set posted values to zero	'Minv_hdr2
              mm2.oswtrvl = 0
              mm2.oswship = 0
              mm2.oswlabor = 0
              mm2.oswparts = 0
              mm2.shipping = 0
              mm2.misc = 0
              mm2.labor = 0
              mm2.taxexemprt = 0
              mm2.parts = 0
              mm2.salestax = 0
              mm2.enter_end(.t.)
              xbasic_wait_for_idle()
              
              kount = count(msquawk->transno,GRP->minv_hdr2)	'(Msquawk->transno,GRP->header)
              
              pct = 18
              ui_modeless_dlg_refresh(msg)
              UI_Yield()
              
              ''Now the child records
              IF kount>0 THEN
              	on error goto broke
              	dim vItemno as C
              	dim i as n
              	i = 1
              	mc.fetch_first(1)				'squawks
              	WHILE .not. mc.fetch_eof()
              		vItemno = mc.itemno
              		result = exist(padl(alltrim(vItemno),4,"0"),"tmp_msquawk","Itemno")
              		if result = .T. then
              '			msgbox(mc.itemno)
              			AddRecords( i, vItemno )
              		end if
              		i = i + 1
              		mc.fetch_next(1)
              	END WHILE
              END IF
              
              pct = 92
              ui_modeless_dlg_refresh(msg)
              UI_Yield()
              
              dim newinvoice as c
              newinvoice = mm2.inv_no
              dim vSite as C
              vSite = mm2.site
              
              pct = 95
              ui_modeless_dlg_refresh(msg)
              UI_Yield()
              
              'Close Opened tables
              tmp_t.close()
              mm2.close()
              mc2.close()
              g11.close()
              g22.close()
              g33.close()
              g44.close()
              g55.close()
              g66.close()
              
              pct = 98
              ui_modeless_dlg_refresh(msg)
              UI_Yield()
              dim Origtotal as N
              Origtotal = topparent:invoicetotal.value
              PleaseWait45(.f.,msg)
              
              finishup:
              
              Parentform.Close(.f.)
              
              dim Frm as P
              Frm = Form.load("MInvoices")
              frm.basequeryrun("site = var->vcLocation","Inv_No")
              'Frm.Index_Set("Site")
              Frm.find(newinvoice)
              Frm.show()
              Frm.activate()
              
              this.enable()	'enable button on way out
              on error goto 0
              
              ui_msg_box("Duplicate Invoice",\
              "Process Completed Successfully.  The new Invoice is "+var->newinvoice+" !",0+64)
              
              END
              
              broke:
              on error goto 0
              PleaseWait45(.f.,msg)
              err_msg = error_text_get(error_code_get())
              err_numb=error_code_get()
              line = error_line_number_get()
              script = error_script_get()
              ui_msg_box("Error",\
              err_msg+" Error occurred at line "+alltrim(str(line,4,0))+" in script: "+script)
              
              END
              
              
              
              FUNCTION AddRecords AS L ( i as N, Itemno as C )
              	
              	dim vdelay as N
              	vdelay = .3		'this time value give a margin of .1, .2 fails
              	
              	curfile = "Copying Discrepancy "+Itemno
              	pct=20+round((i/kount)*60,0)
              	ui_modeless_dlg_refresh(msg)
              	ui_yield()
              
              	'msquawk
              	mc_rec=mc.record_data_get()
              	mc2.enter_begin()
              	mc2.record_data_set(mc_rec)
              	mc2.transno=mm2.transno
              	mc2.enter_end(.t.)
              	mc2.change_begin()
              	xbasic_wait_for_idle()
              	mc2.change_end(.t.)
              	xbasic_wait_for_idle(vdelay)
              	
              	' grandchild1	mfix
              	g1_rec=g1.record_data_get()
              	g11.enter_begin()
              	g11.record_data_set(g1_rec)
              	g11.transno=mc2.transno
              	g11.swkno=mc2.swkno
              	g11.enter_end(.t.)
              	xbasic_wait_for_idle(vdelay)
              	
              	' grandchild2	mlabor
              	g22.batch_begin()
              	g2.fetch_first()
              	WHILE .not. g2.fetch_eof()
              		g2_rec=g2.record_data_get()
              		g22.enter_begin()
              		g22.record_data_set(g2_rec)
              		g22.transno=mc2.transno
              		g22.swkno=mc2.swkno
              		g22.enter_end(.t.)
              		g22.change_begin(.t.)
              		xbasic_wait_for_idle()
              		g22.change_end(.t.)
              		g2.fetch_next()
              		xbasic_wait_for_idle(vdelay)
              	END WHILE
              	g22.batch_end()
              
              	' grandchild3	mparts
              	g33.batch_begin()
              	g3.fetch_first()
              	WHILE .not. g3.fetch_eof()
              		g3_rec=g3.record_data_get()
              		g33.enter_begin()
              		g33.record_data_set(g3_rec)
              		g33.transno=mc2.transno
              		g33.swkno=mc2.swkno
              		g33.enter_end(.t.)
              		g3.fetch_next()
              		xbasic_wait_for_idle(vdelay)
              	END WHILE
              	g33.batch_end()
              	
              	' grandchild4	mship
              	g44.batch_begin()
              	g4.fetch_first()
              	WHILE .not. g4.fetch_eof()
              		g4_rec=g4.record_data_get()
              		g44.enter_begin()
              		g44.record_data_set(g4_rec)
              		g44.transno=mc2.transno
              		g44.swkno=mc2.swkno
              		g44.enter_end(.t.)
              		g4.fetch_next()
              		xbasic_wait_for_idle(vdelay)
              	END WHILE
              	g44.batch_end()
              	
              	' grandchild5	mosw
              	g55.batch_begin()
              	g5.fetch_first()
              	WHILE .not. g5.fetch_eof()
              		g5_rec=g5.record_data_get()
              		g55.enter_begin()
              		g55.record_data_set(g5_rec)
              		g55.transno=mc2.transno
              		g55.swkno=mc2.swkno
              		g55.enter_end(.t.)
              		g5.fetch_next()
              		xbasic_wait_for_idle(vdelay)
              	END WHILE
              	g55.batch_end()
              
              	' grandchild6	mmisc
              	g66.batch_begin()
              	g6.fetch_first()
              	WHILE .not. g6.fetch_eof()
              		g6_rec=g6.record_data_get()
              		g66.enter_begin()
              		g66.record_data_set(g6_rec)
              		g66.transno=mc2.transno
              		g66.swkno=mc2.swkno
              		g66.enter_end(.t.)
              		g6.fetch_next()
              		xbasic_wait_for_idle(vdelay)
              	END WHILE
              	g66.batch_end()	
              END FUNCTION
              
              
              FUNCTION rebuild_minvoices_indexes AS L ()
              	'Update maintenance invoice table indexes after importing a work order.
              	dim table_list as c
              	table_list = <<%list%
              mfix
              minv_hdr2
              mlabor
              mmisc
              mosw
              mparts
              mship
              msquawk
              %list%
              	
              	'convert table_list to long file names
              	table_list = *for_each(x,table.filename_get(x),table_list)
              	'check that all tables in the table_list exist
              	check_exist = *for_each(x,x+"|" + file.exists(x),table_list)
              	missing = filter_string(check_exist,"|False",crlf())
              	IF missing <> "" THEN
              		msg = "Indexes in the following tables will not be updated because the tables cannot be found: " + crlf() + stritran(missing,"|False","")
              		ui_msg_box("Warning",msg,UI_ATTENTION_SYMBOL)
              		table_list = filter_string(check_exist,"|True",crlf())
              		IF table_list = "" THEN
              			ui_msg_box("Error","No tables for which to update indexes.",UI_STOP_SYMBOL)
              			end
              		ELSE
              			table_list = stritran(table_list,"|True","")
              		END IF
              	END IF
              	
              	tables_to_update = table_list
              	
              	dim count as n
              	count = w_count(tables_to_update,crlf())
              	dim i as n
              	dim tbl as p
              	FOR i = 1 TO count
              		table_i = word(tables_to_update,i,crlf())
              		tbl = table.open(table_i)
              		tbl.update_production_index()
              		tbl.close()
              	NEXT i
              END FUNCTION
              
              
              FUNCTION PleaseWait45 AS C (Show = .F.,msg="")
              
              'by using the variable 'msg' in the function, this one function can be used in many
              'different scripts and have a custom message in each script.  This function has a text
              'line
              
              PleaseWait45 = ""
              
              IF msg = "" THEN
              	msg = " Processing Operation"
              END IF
              
              IF show = .F.
              	IF ui_modeless_dlg_exist(msg)
              		ui_modeless_dlg_close(msg)
              	END IF
              	exit function
              END IF
              
              dim shared pct as N
              box_code = <<%dlg%
              {background=Dirty White}
              {font=calibri,18,i}
                {text=65curFile};    
              {'};
              {font=arial,12}
              {sp=32}{text=4pct}%;
                {progress=60pct}  {'};
              {'};
              %dlg%
              
              ui_modeless_dlg_box(msg,box_code)
              'copy the next 2 lines to change the progress bar.  
              'Change the "PCT=" amount to move the bar.
              pct=1
              ui_modeless_dlg_refresh(msg)
              
              box_event = <<%code%
              2=2
              %code%
              
              ui_modeless_dlg_box(msg,box_code,box_event)
              ui_modeless_dlg_setfocus(msg)
              ui_modeless_dlg_refresh(msg)
              
              END FUNCTION
              Attached Files
              Alpha 5 Version 11
              AA Build 2999, Build 4269, Current Build
              DBF's and MySql
              Desktop, Web on the Desktop and WEB

              Ron Anusiewicz

              Comment


                #8
                Re: Back to duplicating a record with child tables.

                I am going to have to study all of this and see if I can understand how it would know which record of the child tables to duplicate.

                I need to figure this out for two sets. One is all one to one and the other is 1 - one to one and one one to many.


                This one should be easy but I keep getting an "Not an open index" error if you try and go to another record once you have run the duplicate record script.




                This one duplicates the parent, a one to many child and also needs to duplicate 1 one to one. I can get it to work perfectly with just the parent and the one to many but when I try to also include the one to one, I get the "Not an open index" error if you try and change to another record once the script it run. Also when including the one to one child, the data actually gets copied into a new record but does not show up until you exit the form and then reload it.
                Attached Files

                Comment


                  #9
                  Re: Back to duplicating a record with child tables.

                  I don't know if this will help, but here's a tiny app demonstrating some of what I did.

                  Ron
                  Attached Files
                  Alpha 5 Version 11
                  AA Build 2999, Build 4269, Current Build
                  DBF's and MySql
                  Desktop, Web on the Desktop and WEB

                  Ron Anusiewicz

                  Comment


                    #10
                    Re: Back to duplicating a record with child tables.

                    Thanks Ronald.

                    This gives me a better understanding of how this works with the record_data_get and record_data_set methods

                    I took what you sent and modified the work_orders form to contain a tabbed object and then placed the items browse on the first tab and the stuff on the second. Also the original form you included would not allow changes for some reason so I had to totally recreate it.

                    This sort of replicates my actual form on a very simplified manner.

                    Trying code based on what was posted in a 2007 thread, it caused the tab focus to change and the form to flash as shown in the video. This code does not change the tab focus or cause flashing. At least not in this example. Will see what happens when I modify it for my actual app.

                    I did find a bug. You had the Inv_ID as type c and this worked until the count got to 10. Once it was over 10 then the wo_items table would start adding more items than was in the record count to be duplicated. I changed the Inv_ID to type N in all tables and then changed the variables in the script to reflect Type N. My Inv_id fields are all type N anyway so this change will work with my tables.

                    The other thing I noticed was the

                    Code:
                    Parentform.Close(.f.)
                    xbasic_wait_for_idle()
                    
                    dim Frm as P
                    Frm = Form.load("work_orders")
                    Frm.Index_Set("inv_id")
                    Frm.find(newinvoice)
                    Frm.show()
                    Frm.activate()
                    
                    this.enable()	'enable button on way out
                    would close the form and then reopen it as Work_order0 . Then the next time it would open as Work_order.

                    Not a big deal but just removing the above code and changing it to just topparent.fetch_last() solved that.

                    Again, thank you, thank you, thank you. You example code actually made sense to me and hopefully will give me a good starting point. Will report back once I try it.

                    Comment


                      #11
                      Re: Back to duplicating a record with child tables.

                      Ron seems to have fixed the zip - works great. I can think of several places I can use a variation of this script - thanks Ron!
                      Robin

                      Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

                      Comment


                        #12
                        Re: Back to duplicating a record with child tables.

                        Well I have it all working.

                        I modified the code Ron posted to fit my actual needs. I did find out that if I removed the "Parentform.Close()" section of the code and replaced it with "topparent.fetch_last()", it would work but would not populate the one to many even on the form though the data was there. If you closed the form and then reopened it, it would then show the data. As a result I just put the "Parentform.Close()" section of code back in.

                        Again, a big thank you to Ron.

                        Comment


                          #13
                          Re: Back to duplicating a record with child tables.

                          Your Welcome. I'm glad I could help.
                          Alpha 5 Version 11
                          AA Build 2999, Build 4269, Current Build
                          DBF's and MySql
                          Desktop, Web on the Desktop and WEB

                          Ron Anusiewicz

                          Comment


                            #14
                            Re: Back to duplicating a record with child tables.

                            Still having some issues with this.

                            Seems if you remove the Parentform.close() section of the code and replace it with topparent.fetch_last(), everyhting works perfectly except it will not populate the one to many fields on the form even though the underlying data is there.

                            If you leave the Parentform.close() section of the code it will populate the one to many fields on the form. BUT now all code references that are explicit no longer work and will throw errors. This is because the form gets reopened with a number behind the name. In my case the "estimates" form would now be "estimates0" until it is closed and reopened again. This means code like "ESTIMATES.QUERY_CLEAR()" no longer work because it is explicit.

                            So now I need to decide if I am going to track down every place in all my code that is run from or has to do with that form and make sure it never makes an explicit reference or I need to figure out how to just use topparent.fetch_last() and then get the one to many data fields on the form to populate.

                            Comment


                              #15
                              Re: Back to duplicating a record with child tables.

                              It sounds like there is a timing issue where the new form is opening before the first form closes. That's why the second form has a number at the end.
                              The xbasic_wait _for_idle is an attempt to have the first form close before the second form opens.

                              Code:
                              Parentform.Close(.f.)
                              xbasic_wait_for_idle()
                              
                              dim Frm as P
                              Frm = Form.load("work_orders")
                              Frm.Index_Set("inv_id")
                              Frm.find(newinvoice)
                              Frm.show()
                              Frm.activate()
                              
                              this.enable()	'enable button on way out
                              That said, I always try to avoid explicit code just for this reason
                              Alpha 5 Version 11
                              AA Build 2999, Build 4269, Current Build
                              DBF's and MySql
                              Desktop, Web on the Desktop and WEB

                              Ron Anusiewicz

                              Comment

                              Working...
                              X