Use a check box to duplicate data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • liverbarry
    New Member
    • Nov 2007
    • 16

    Use a check box to duplicate data

    I have a table coalled tAddress, which includes fields street, Suburb, city, home Phone

    I have another table called tNOK (next of Kin) and the same address fields,

    using subforms to enter data I also have a check box calle chkSameAsPerson

    how can I get the check box to enter tAddress into tNOK and display it immediately on the form

    both tables have a FK which is PersonID related to intial table, tPersonDetails
    Do I need to relate the two tables directly first?

    any help is much appreciated

    Barry
  • Delerna
    Recognized Expert Top Contributor
    • Jan 2008
    • 1134

    #2
    On the code page for the form and in the click event for the cechbox
    something like this should work
    [code=vb]
    Private Sub chkSameAsPerson _click()
    Dim db As DAO.Database
    Dim strSQL As String

    Set db = CurrentDb
    strSQL = "UPDATE tNOK SET street='" & TheNameOfThestr eetTextbox & "' WHERE TheRelatedField =" TheNameOfTheRel atedFieldTextbo x
    db.Execute strSQL
    Set db = Nothing
    End Sub
    [/code]

    Bear in mind that the above will not a work. It is merely an example as you do not have enough info in your question.
    So take the above, adjust it to suit your particular problem and use the help files to guide you.

    Note that since the controls that contain the address you want to copy are on a subform you will need to take that into account when referencing TheNameOfThestr eetTextbox and TheNameOfTheRel atedFieldTextbo x etc.

    Have a go youself, you will learn more that way. If you stike a barrier then come back and ask here.


    PS. The above is only one way to achieve what you want, there are other ways.

    Comment

    • liverbarry
      New Member
      • Nov 2007
      • 16

      #3
      Hi, I'm struggling here!!

      I have a form called fSubDemogs with two subforms fPtAddress and fNOKAddress.

      text box on fPtaddress is TxtPtStreet underlying field is 'Street' from table tPatientAddress '

      check box will then put same info into TxtNOKStreet on form fNOKAddress

      underlying field is NOKStreet in table tNOK

      can you give me anymore info
      Many Thanks

      Originally posted by Delerna
      On the code page for the form and in the click event for the cechbox
      something like this should work
      [code=vb]
      Private Sub chkSameAsPerson _click()
      Dim db As DAO.Database
      Dim strSQL As String

      Set db = CurrentDb
      strSQL = "UPDATE tNOK SET street='" & TheNameOfThestr eetTextbox & "' WHERE TheRelatedField =" TheNameOfTheRel atedFieldTextbo x
      db.Execute strSQL
      Set db = Nothing
      End Sub
      [/code]

      Bear in mind that the above will not a work. It is merely an example as you do not have enough info in your question.
      So take the above, adjust it to suit your particular problem and use the help files to guide you.

      Note that since the controls that contain the address you want to copy are on a subform you will need to take that into account when referencing TheNameOfThestr eetTextbox and TheNameOfTheRel atedFieldTextbo x etc.

      Have a go youself, you will learn more that way. If you stike a barrier then come back and ask here.


      PS. The above is only one way to achieve what you want, there are other ways.

      Comment

      • Delerna
        Recognized Expert Top Contributor
        • Jan 2008
        • 1134

        #4
        OK, I will do a mock up database so that I can get the solution right according to what you have and get back to you

        Comment

        • Delerna
          Recognized Expert Top Contributor
          • Jan 2008
          • 1134

          #5
          OK, with the extra info you have provided, here is the easiest way for you to do it.
          [code=vb]
          Private Sub chkSameAsPerson _Click()
          Forms!fSubDemog s.fNOKAddress.F orm!TxtNOKStree t = Forms!fSubDemog s.fPtaddress.Fo rm!TxtPtStreet
          End Sub
          [/code]


          For your information,to do it with my original suggestion
          would be something like this

          [code=vb]
          Private Sub chkSameAsPerson _click()
          Dim db As DAO.Database
          Dim strSQL As String

          Set db = CurrentDb
          strSQL = "UPDATE tNOK SET street='" & Forms!fSubDemog s.fPtaddress.Fo rm!TxtPtStreet & "' WHERE TheRelatedField =" TheNameOfTheRel atedFieldTextbo x
          db.Execute strSQL
          Set db = Nothing
          me.refresh
          End Sub
          [/code]

          I still don't know what the related field is. I guess it would be something like patientID

          Comment

          Working...