CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge -> General/Other

 Copy record

Print topic Send  topic

Author Message
Fred
Posted: 02/04/2004, 4:40 PM

Is there a way to copy a record for an insert? So for example if I have an Task record and want to use it as the template for a new record. I know this can be done in CCs, but I need to do it for a CC project.

thanks
peterr


Posts: 5971
Posted: 02/04/2004, 5:06 PM

Which programming language are you using...?

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Fred
Posted: 02/04/2004, 7:01 PM

sorry, asp
peterr


Posts: 5971
Posted: 02/04/2004, 7:22 PM

Thanks. A few more details would help:
Do you want to copy a record to another table after it was submitted/inserted. In other words: create two records instead of one?
Or do you want to display one record but update another one?

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Fred
Posted: 02/05/2004, 6:24 AM

Thanks for following up ! I want to use the first record as a template. Sofor example, I have a task record that has a lot of field - job number, phase, module, due date, assign to, etc. I want to create a new record that has all the information from an existing record, but that I can make a couple of changes to then save.
So ideally, while the first record is displayed, there would be a "Copy button" that would be the equivalent of an Insert button, but would not clear all the fields, only the key field.
thanks,

Fred

Nicole

Posts: 586
Posted: 02/06/2004, 5:14 AM

Hello,
Here is brief description how to create Copy button in CodeCharge.
ASP + Templates version.
If you want to copy a record into the same table the solution is pretty simple. Since CC doesn't allow editing HTML code inside the application you have to edit .html file. I suggest that you do it after the page design is complete. Open HTML code and find Update button:
  
<!--BeginBookUpdate-->  
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>  
<!--EndBookUpdate-->  
Just add similar button with "Insert" action:
  
<!--BeginBookUpdate-->  
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>  
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'insert';"/>  
<!--EndBookUpdate-->  
that's all.

If you want to copy the record into different table use a bit different way:
1.create copy button as described above, but with "Copy" action
  
<!--BeginBookUpdate-->  
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>  
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'copy';"/>  
<!--EndBookUpdate-->  
2.open form's Custom Action event and obtain generated code. You see that there're three actions: insert, update, delete. Just add forth copy action:
  
case "copy"  
      sSQL = "insert into items_copy_table (" & _  
          "[name]," & _  
          "[author]," & _  
          "[category_id]," & _  
          "[price]," & _  
          "[product_url]," & _  
          "[image_url]," & _  
          "[notes]," & _  
          "[is_recommended])" & _  
          " values (" & _  
          ToSQL(fldname, "Text") & "," & _  
          ToSQL(fldauthor, "Text") & "," & _  
          ToSQL(fldcategory_id, "Number") & "," & _  
          ToSQL(fldprice, "Number") & "," & _  
          ToSQL(fldproduct_url, "Text") & "," & _  
          ToSQL(fldimage_url, "Text") & "," & _  
          ToSQL(fldnotes, "Text") & "," & _  
          fldis_recommended & _  
          ")"  
 end select  

Templateless version
The solution is very much similar to template version. The only difference is that you can create Custom Show event for the form, obtain generated code and edit HTML there.

_________________
Regards,
Nicole
View profile  Send private message
jayme27
Posted: 02/06/2004, 6:53 AM

Where can I find the CCS template for cloning a recordset?
Already tried the REX website and couldn't find it.
peterr


Posts: 5971
Posted: 02/06/2004, 3:02 PM

jayme27,
I don't know about such template, or REX website, but I recommend that you post your question to our CCS forums, possibly with more details.

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
fred
Posted: 02/07/2004, 6:48 AM

thanks,

will try this out this weekend!

I appreciate the prompt responses.
Tony M
Posted: 02/08/2004, 10:00 AM

Hello there
As a result of this thread...I've just gone back to an .asp CC Project and placed a "Copy Button" on a CC Form...using the code mentioned...BUT it doesn't appear to copy a record as suggested.

I would appreciate any additional help that can be offered.
Regards
Tony M
peterr


Posts: 5971
Posted: 02/08/2004, 2:19 PM

The above code was just an example and should be adapted to your own table structure.
I probably cannot help you without knowing any details about what happened and what means "doesn't appear to copy ", but generally one or several of the following should happen:
1. The record would be copied to another record in the same table.
Check your database.
2. The record would be copied to another record in another table. Check your database.
3. There would be an error displayed on the page.
4. The page would be refreshed.
5. The page would be redirected to another page.

Which of the above, or something else, happened?

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Tony M
Posted: 02/08/2004, 4:46 PM

Thanks again Peter for a very quick response and on a SUNDAY as well...those that ask...are very lucky and grateful :-D

I was refering to Nicole's answer...where she said
-------------------------------------------------------------------------------------
Here is brief description how to create Copy button in CodeCharge.
ASP + Templates version.
If you want to copy a record into the same table the solution is pretty simple. Since CC doesn't allow editing HTML code inside the application you have to edit .html file. I suggest that you do it after the page design is complete. Open HTML code and find Update button:

<!--BeginBookUpdate-->
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>
<!--EndBookUpdate-->

Just add similar button with "Insert" action:


<!--BeginBookUpdate-->
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'insert';"/>
<!--EndBookUpdate-->

that's all.
-----------------------------------------------------------------------
I changed Nicole's code to suit my table etc BUT the copy button only updated the record selected...it did not duplicate the record at all'

Your help is very much appreciated.
Regards
Tony M
peterr


Posts: 5971
Posted: 02/08/2004, 4:52 PM

OK. Not sue if you understand that Nicole has shown 2 different solutions.
Since you wrote that you changed Nicole's code then it means that you selected the 2nd solution. But your HTML changes apply to the 1st solution. Therefore instead of the HTML changes that you've shown, please make the other HTML changes that she described:

<!--BeginBookUpdate-->
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'copy';"/>
<!--EndBookUpdate-->

_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Tony M
Posted: 02/08/2004, 6:25 PM

Yes Peter..I understood that Nicole showed two examples.

As I only want to copy a record into the same table I only used Nicole's first example...listed below

<!--BeginBookUpdate-->
<input type="submit" value="Update" onclick="document.Book.FormAction.value = 'update';"/>
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'insert';"/>
<!--EndBookUpdate-->

I just changed Nicole's example to match my table etc

In this example Nicole does not suggest using the...form's Custom Action event

So I only added her...second line...to my code
<input type="submit" value="Copy" onclick="document.Book.FormAction.value = 'insert';"/>

Regards
Tony M
Nicole

Posts: 586
Posted: 02/09/2004, 12:29 AM

Tony,
Please check that you can insert the record with Insert button. If it works please add debug code as described to check out what happens with your form. Create Custom Action event and find these lines:
  
'-------------------------------  
' Create SQL statement  
'-------------------------------  
  select case sAction  
    case "insert"  
' SQL build code  
...  
case "update"  
modify code to get:
  
response.write "Action:" & sAction & "<br>"  
'-------------------------------  
' Create SQL statement  
'-------------------------------  
  select case sAction  
    case "insert"  
' SQL build code  
...  
response.write sSQL & "<br>"  
case "update"  
Then test Copy button and check what action is identified and if query is printed. If you get "insert" action printed and correct query then it means that SQL will be executed. Lets check it.

_________________
Regards,
Nicole
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.