Welcome to SPN

Register and Join the most happening forum of Sikh community & intellectuals from around the world.

Sign Up Now!
  1. Monthly (Recurring) Target: $300 :: Achieved: $95
      Become a Supporter    ::   Make a Contribution   

Update a table based on current record

Discussion in 'Information Technology' started by CAT, Jul 28, 2006.

  1. CAT

    CAT
    Expand Collapse
    Guest

    I have two tables one that stores information regaring food, portion, cal and
    fat(called tblpantry). The other table stores Journaling of the
    day(tbljournaling. I want to be able to select an item in the form that I
    created for journaling and have that information then stored in the
    journaling table. Is there a way to copy a record that is selected to a
    different table? If so how?
     
  2. Loading...


  3. Pieter Wijnen

    Pieter Wijnen
    Expand Collapse
    Guest

    Sub btnUpdJournal_click()
    Dim Db AS DAO.Database
    Dim RsAdd AS DAO.Recordset
    Dim RsC AS DAO.Recordset
    Dim Fld AS DAO.Field

    Set Db = Access.CurrentDb
    Set RsAdd = Db.OpenRecordset("JOURNAL",DAO.DbOpenDynaset, DAO.dbAppendOnly)
    ' Open an updatable/appendable Cursor against the Table
    RsAdd.AddNew ' Add new entry
    Set RsC = Me.RecordsetClone ' copy of form's data
    RsC.BookMark = Me.Bookmark ' Move to the selected record

    For Each Fld In RsC.Fields ' Loop through the Fields, Assume all fields in
    "Parent" in "Child" Else use If's
    RsAdd.Fields(Fld.Name) = Fld.Value
    Next 'Fld

    RsAdd.Update
    RsAdd.Close : Set RsAdd=Nothing
    Set RsC = Nothing
    Set Db = Nothing ' Close all objects
    End Sub

    HTH

    Pieter




    "CAT" <CAT@discussions.microsoft.com> wrote in message
    news:C5BC0F00-8B97-47E2-A270-0F553AEFE5E5@microsoft.com...
    >I have two tables one that stores information regaring food, portion, cal
    >and
    > fat(called tblpantry). The other table stores Journaling of the
    > day(tbljournaling. I want to be able to select an item in the form that I
    > created for journaling and have that information then stored in the
    > journaling table. Is there a way to copy a record that is selected to a
    > different table? If so how?
     
  4. CAT

    CAT
    Expand Collapse
    Guest

    So does the button for this need to be on the form for the journal table or
    on the subform for the pantry table where the record is that will be copied
    to the journal table???

    Thanks

    "Pieter Wijnen" wrote:

    > Sub btnUpdJournal_click()
    > Dim Db AS DAO.Database
    > Dim RsAdd AS DAO.Recordset
    > Dim RsC AS DAO.Recordset
    > Dim Fld AS DAO.Field
    >
    > Set Db = Access.CurrentDb
    > Set RsAdd = Db.OpenRecordset("JOURNAL",DAO.DbOpenDynaset, DAO.dbAppendOnly)
    > ' Open an updatable/appendable Cursor against the Table
    > RsAdd.AddNew ' Add new entry
    > Set RsC = Me.RecordsetClone ' copy of form's data
    > RsC.BookMark = Me.Bookmark ' Move to the selected record
    >
    > For Each Fld In RsC.Fields ' Loop through the Fields, Assume all fields in
    > "Parent" in "Child" Else use If's
    > RsAdd.Fields(Fld.Name) = Fld.Value
    > Next 'Fld
    >
    > RsAdd.Update
    > RsAdd.Close : Set RsAdd=Nothing
    > Set RsC = Nothing
    > Set Db = Nothing ' Close all objects
    > End Sub
    >
    > HTH
    >
    > Pieter
    >
    >
    >
    >
    > "CAT" <CAT@discussions.microsoft.com> wrote in message
    > news:C5BC0F00-8B97-47E2-A270-0F553AEFE5E5@microsoft.com...
    > >I have two tables one that stores information regaring food, portion, cal
    > >and
    > > fat(called tblpantry). The other table stores Journaling of the
    > > day(tbljournaling. I want to be able to select an item in the form that I
    > > created for journaling and have that information then stored in the
    > > journaling table. Is there a way to copy a record that is selected to a
    > > different table? If so how?

    >
    >
    >
     
  5. xRoachx

    xRoachx
    Expand Collapse
    Guest

    Hi CAT -- Before you go further you should note it appears you may have a
    design problem. A properly normalized database should not have the exact
    information stored in two tables.

    What is the relationship between tblpantry and tbljournal? What exactly are
    you trying to accomplish?

    "CAT" wrote:

    > So does the button for this need to be on the form for the journal table or
    > on the subform for the pantry table where the record is that will be copied
    > to the journal table???
    >
    > Thanks
    >
    > "Pieter Wijnen" wrote:
    >
    > > Sub btnUpdJournal_click()
    > > Dim Db AS DAO.Database
    > > Dim RsAdd AS DAO.Recordset
    > > Dim RsC AS DAO.Recordset
    > > Dim Fld AS DAO.Field
    > >
    > > Set Db = Access.CurrentDb
    > > Set RsAdd = Db.OpenRecordset("JOURNAL",DAO.DbOpenDynaset, DAO.dbAppendOnly)
    > > ' Open an updatable/appendable Cursor against the Table
    > > RsAdd.AddNew ' Add new entry
    > > Set RsC = Me.RecordsetClone ' copy of form's data
    > > RsC.BookMark = Me.Bookmark ' Move to the selected record
    > >
    > > For Each Fld In RsC.Fields ' Loop through the Fields, Assume all fields in
    > > "Parent" in "Child" Else use If's
    > > RsAdd.Fields(Fld.Name) = Fld.Value
    > > Next 'Fld
    > >
    > > RsAdd.Update
    > > RsAdd.Close : Set RsAdd=Nothing
    > > Set RsC = Nothing
    > > Set Db = Nothing ' Close all objects
    > > End Sub
    > >
    > > HTH
    > >
    > > Pieter
    > >
    > >
    > >
    > >
    > > "CAT" <CAT@discussions.microsoft.com> wrote in message
    > > news:C5BC0F00-8B97-47E2-A270-0F553AEFE5E5@microsoft.com...
    > > >I have two tables one that stores information regaring food, portion, cal
    > > >and
    > > > fat(called tblpantry). The other table stores Journaling of the
    > > > day(tbljournaling. I want to be able to select an item in the form that I
    > > > created for journaling and have that information then stored in the
    > > > journaling table. Is there a way to copy a record that is selected to a
    > > > different table? If so how?

    > >
    > >
    > >
     
Since you're here... we have a small favor to ask...

More people are visiting & reading SPN than ever but far fewer are paying to sustain it. Advertising revenues across the online media have fallen fast. So you can see why we need to ask for your help. Donating to SPN's is vote for free speech, for diversity of opinions, for the right of the people to stand up to religious bigotry. Without any affiliation to any organization, this constant struggle takes a lot of hard work to sustain as we entirely depend on the contributions of our esteemed writers/readers. We do it because we believe our perspective matters – because it might well be your perspective, too... Fund our efforts and together we can keep the world informed about the real Sikh Sikhi Sikhism. If everyone who writes or reads our content, who likes it, helps us to pay for it, our future would be much more secure. Every Contribution Matters, Contribute Generously!

    Become a Supporter      ::     Make a Contribution     



Share This Page