OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

[Solved] Macro- Form, copy one record field to another table

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
master-plan
General User
General User


Joined: 29 Mar 2012
Posts: 8

PostPosted: Mon Apr 02, 2012 8:47 pm    Post subject: [Solved] Macro- Form, copy one record field to another table Reply with quote

Dear all,

From within a Form I'd like to copy a selected record to a separate table.

Say I've got a list of items, and I want to select an entire record and copy it to another table. Or if easier, then just copy a single field from a Form to another table. What's the Macro Basic code for this?

Any help sincerely appreciated.
Ahmed the rookie


Last edited by master-plan on Mon Apr 30, 2012 11:05 pm; edited 2 times in total
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Mon Apr 02, 2012 11:18 pm    Post subject: Reply with quote

Hello

Maybe this thread Base - Copy column and copy row functions can help you.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
master-plan
General User
General User


Joined: 29 Mar 2012
Posts: 8

PostPosted: Tue Apr 03, 2012 3:19 am    Post subject: Reply with quote

Dear Romke,

Uhmm... I've gone through your suggested thread. But it does not quite address the problem at hand.

In particular in the fact that I want to copy one selected field (or entire record if that's easier) in a Form to an altogether different table (and not to the same table). (That is a different table to the one referenced in the Form Properties/ Content box).

Thanks nonetheless.
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Tue Apr 03, 2012 4:39 am    Post subject: Reply with quote

Hello

It is not so clear to me what you want there I see not any start of a solution of your problem. When you want only copy one field then maybe this can help you.

http://www.oooforum.org/forum/viewtopic.phtml?t=132192&highlight=copy+field+sub

I don't know if it is a good idea to copy a value from one table to an other table. In stead of copy a value you can use maybe a listbox.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
RPG
Super User
Super User


Joined: 24 Apr 2008
Posts: 2697
Location: Apeldoorn, Netherland

PostPosted: Tue Apr 03, 2012 5:03 am    Post subject: Reply with quote

Hello

I think it is a good idea before you follow your own idea read first a set of tutorials. The forum tutorials special for base is a good place to start. Then you get a good idea from who has a good understanding of OOo-base and databases. Do not read all tutorials complete but start with reading them partly(by skimming). Then you see what is the best methode for you and your skills. Try to avoid macros they are real difficult and how more time you spend on macros how less you can send to the real stuff as SQL. I think read special posts of Villeroy, Arineckaig and DACM for SQL read posts of Sliderule.

I think when you first try to understand what you can do with listboxes that can help you a lot and speed up your work.

Romke
_________________
OOo 3.4.5 on openSUSE 12.1
Use this forum : http://user.services.openoffice.org/en/forum
Back to top
View user's profile Send private message
master-plan
General User
General User


Joined: 29 Mar 2012
Posts: 8

PostPosted: Tue Apr 03, 2012 9:48 am    Post subject: Reply with quote

Idea

Hi Romke,

Thanks for the links. I think I'm getting some ideas reading from the other threads. (I'm now considering the use of a sub form).

I'll continue working with this problem. If I manage to make it work I'll update the post as solved and outline solution.
Back to top
View user's profile Send private message
master-plan
General User
General User


Joined: 29 Mar 2012
Posts: 8

PostPosted: Mon Apr 30, 2012 9:57 pm    Post subject: Reply with quote

Dear all,

Ok. After weeks of hitting my head against the keyboard I finally got it to work. I'm sharing my code below in case this is of help to others struggling with similar problems.

*Note* If the code reads amateurishly, please refrain from laughing... this is my best Razz


Code:
Sub ReadWriteCode(oEvent As Object)
   'Declaring Objects and Strings
   Dim MyForm As Object
   Dim MyFieldID, MyFieldINV_ID, MyFieldPR_ID,MyFieldINV_SEQ,MyFieldINV_AMNT,MyFieldINV_AFE01,MyFieldINV_BDGT01,MyFieldINV_SUB_DATE,MyFieldINV_NOTES,MyFieldPAYRQ_ID,MyFieldSIG_STATUS,MyFieldADD_NOTES As Object
   Dim MyTextID, MyTextINV_ID, MyTextPR_ID,MyTextINV_SEQ,MyTextINV_AMNT,MyTextINV_AFE01,MyTextINV_BDGT01,MyTextINV_SUB_DATE,MyTextINV_NOTES,MyTextPAYRQ_ID,MyTextSIG_STATUS,MyTextADD_NOTES As String
   Dim MyFieldNameID, MyFieldNameINV_ID, MyFieldNamePR_ID,MyFieldNameINV_SEQ,MyFieldNameINV_AMNT,MyFieldNameINV_AFE01,MyFieldNameINV_BDGT01,MyFieldNameINV_SUB_DATE,MyFieldNameINV_NOTES,MyFieldNamePAYRQ_ID,MyFieldNameSIG_STATUS,MyFieldNameADD_NOTES As String

   'Defining FieldName Strings per Form Fields
   MyFieldNameID = "PAYRQ_ID"
   MyFieldNameINV_ID = "INV_ID"
   MyFieldNamePR_ID = "PR_ID"
   MyFieldNameINV_SEQ = "INV_SEQ"
   MyFieldNameINV_AMNT = "INV_AMNT"
   MyFieldNameINV_AFE01 = "INV_AFE01"
   MyFieldNameINV_BDGT01 =   "INV_BDGT01"
   MyFieldNameINv_SUB_DATE = "INV_SUB_DATE"
   MyFieldNameINV_NOTES = "INV_NOTES"
   MyFieldNamePAYRQ_ID = "PAYRQ_ID"
   MyFieldNameSIG_STATUS =   "SIG_STATUS"
   MyFieldNameADD_NOTES = "ADD_NOTES"
      
   'Defining MyForm Object. MainForm is the name of the "Form" inside my FRM_PAYMENTS Form.
   MyForm = ThisComponent.Drawpage.Forms.getbyName("MainForm")

   'Read values and store in Strings variables.   
   MyFieldID = MyForm.Columns.GetByName(MyFieldNameID)
   MyTextID = MyFieldID.Value
   MyFieldINV_ID = MyForm.Columns.GetByName(MyFieldNameINV_ID)
   MyTextINV_ID = MyFieldINV_ID.Value
   MyFieldPR_ID = MyForm.Columns.GetByName(MyFieldNamePR_ID)
   MyTextPR_ID = MyFieldPR_ID.Value
   MyFieldINV_SEQ = MyForm.Columns.GetByName(MyFieldNameINV_SEQ)
   MyTextINV_SEQ = MyFieldINV_SEQ.Value
   MyFieldINV_AMNT = MyForm.Columns.GetByName(MyFieldNameINV_AMNT)
   MyTextINV_AMNT = MyFieldINV_AMNT.Value
   MyFieldINV_AFE01 = MyForm.Columns.GetByName(MyFieldNameINV_AFE01)
   MyTextINV_AFE01 = MyFieldINV_AFE01.Value
   MyFieldINV_BDGT01 = MyForm.Columns.GetByName(MyFieldNameINV_BDGT01)
   MyTextINV_BDGT01 = MyFieldINV_BDGT01.Value
   MyFieldINV_SUB_DATE = MyForm.Columns.GetByName(MyFieldNameINV_SUB_DATE)
   MyTextINV_SUB_DATE = MyFieldINV_SUB_DATE.Value
   MyFieldINV_NOTES = MyForm.Columns.GetByName(MyFieldNameINV_NOTES)
   MyTextINV_NOTES = MyFieldINV_NOTES.Value
   MyFieldPAYRQ_ID = MyForm.Columns.GetByName(MyFieldNamePAYRQ_ID)
   MyTextPAYRQ_ID = MyFieldPAYRQ_ID.Value
   MyFieldSIG_STATUS = MyForm.Columns.GetByName(MyFieldNameSIG_STATUS)
   MyTextSIG_STATUS = MyFieldSIG_STATUS.Value
   MyFieldADD_NOTES = MyForm.Columns.GetByName(MyFieldNameADD_NOTES)
   MyTextADD_NOTES = MyFieldADD_NOTES.Value
   
   'Declaring Objects and Strings for second form inside my FRM_PAYMENTS Form.
   Dim MyForm2 As Object
   Dim MyFieldName2 As String
   Dim MyFieldTR_ID, MyFieldTR_PRID, MyFieldTR_INV_ID, MyFieldTR_INV_SEQ, MyFieldTR_AFE, MyFieldTR_BDGT, MyFieldTR_AMNT, MyFieldTR_SUB_DATE, MyFieldTR_NOTES, MyFieldTR_SIG_STATUS, MyFieldTS_TIME, MyFieldTS_DATE As Object
   Dim MyTextTR_INV_ID, MyTextTR_INV_SEQ, MyTextTR_AFE, MyTextTR_BDGT, MyTextTR_AMNT, MyTextTR_SUB_DATE, MyTextTR_NOTES, MyTextTR_SIG_STATUS As String

   MyFieldNameTR_ID = "TR_ID"
   MyFieldNameTR_PRID = "TR_PRID"
   MyFieldNameTR_INV_ID = "TR_INV_ID"
   MyFieldNameTR_INV_SEQ = "TR_INV_SEQ"
   MyFieldNameTR_AFE = "TR_AFE"
   MyFieldNameTR_BDGT = "TR_BDGT"
   MyFieldNameTR_AMNT = "TR_AMNT"
   MyFieldNameTR_SUB_DATE = "TR_SUB_DATE"
   MyFieldNameTR_NOTES = "TR_NOTES"
   MyFieldNameTR_SIG_STATUS = "TR_SIG_STATUS"

   'Defining MyForm2 Object. ChangeForm is the name of the second "Form" (at same level, not indented) inside my FRM_PAYMENTS Form.
   MyForm2 = ThisComponent.Drawpage.Forms.getbyName("ChangeForm")
   
   MyForm2.moveToInsertRow()

   'Write values into the Form "ChangeForm".
   MyFieldTR_ID = MyForm2.Columns.GetByName(MyFieldNameTR_ID)
   MyFieldTR_ID.Value = MyTextID
   MyFieldTR_PRID = MyForm2.Columns.GetByName(MyFieldNameTR_PRID)
   MyFieldTR_PRID.Value = MyTextPR_ID
   MyFieldTR_INV_ID = MyForm2.Columns.GetByName(MyFieldNameTR_INV_ID)
   MyFieldTR_INV_ID.Value = MyTextINV_ID
   MyFieldTR_INV_SEQ = MyForm2.Columns.GetByName(MyFieldNameTR_INV_SEQ)
   MyFieldTR_INV_SEQ.Value = MyTextINV_SEQ
   MyFieldTR_AFE = MyForm2.Columns.GetByName(MyFieldNameTR_AFE)
   MyFieldTR_AFE.Value = MyTextINV_AFE01
   MyFieldTR_BDGT = MyForm2.Columns.GetByName(MyFieldNameTR_BDGT)
   MyFieldTR_BDGT.Value = MyTextINV_BDGT01
   MyFieldTR_AMNT = MyForm2.Columns.GetByName(MyFieldNameTR_AMNT)
   MyFieldTR_AMNT.Value = MyTextINV_AMNT
   MyFieldTR_SUB_DATE = MyForm2.Columns.GetByName(MyFieldNameTR_SUB_DATE)
   MyFieldTR_SUB_DATE.Value = MyTextINV_SUB_DATE
   MyFieldTR_NOTES = MyForm2.Columns.GetByName(MyFieldNameTR_NOTES)
   MyFieldTR_NOTES.Value = MyTextINV_NOTES
   MyFieldTR_SIG_STATUS = MyForm2.Columns.GetByName(MyFieldNameTR_SIG_STATUS)
   MyFieldTR_SIG_STATUS.Value = MyTextSIG_STATUS
   
   Dim MyTextTS_TIME As string
   Dim MyFieldNameTS_TIME, MyFieldNameTS_DATE As String
   
   MyTextTS_TIME = NOW()
   MyFieldNameTS_TIME = "TS_TIME"
   
   MyFieldTS_TIME = MyForm2.Columns.GetByName(MyFieldNameTS_TIME)
   MyFieldTS_TIME.Value = MyTextTS_TIME
   
   MyForm2.insertRow()
   
End Sub
[/code]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group