Code for a button to send the data to a linked table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DanniiD
    New Member
    • Sep 2015
    • 2

    Code for a button to send the data to a linked table

    Hello. I am trying to make my life easier by using data from one table, then adding some additional text boxes to the form to contain other information that another table requires.

    I have created a form that has some bound text boxes (displays the data from the table work pack register)and some that are not bound because these are the additional text boxes for the information required in the other table.

    Then i would like to add a button that sends all the data to the table document which is a table that exists in another database but I have linked it to the database i am working in. I am creating this so that I don't have to retype all the data when most of it already exists.

    Can anyone help me with this? I have looked and found some examples but none that work for me.

    I just need help with the code for the button.
    Last edited by DanniiD; Sep 24 '15, 04:32 AM. Reason: added additional information
  • madankarmukta
    Contributor
    • Apr 2008
    • 308

    #2
    Can you please put the code you tried, also put on more on why you want to add a button to the form as you can update the table in the postback itself.

    Best Regard.

    Comment

    • DanniiD
      New Member
      • Sep 2015
      • 2

      #3
      Hi there,

      below is what i was playing with to start with:

      Code:
      Set db = CurrentDb
      Set rec = db.OpenRecordset("Select * from Document")
      
      rec.AddNew
      rec("Document Number") = Me.DocumentNumber
      rec("Document Title") = Me.DocumentTitle
      rec("Description") = Me.Description
      rec("Location") = Me.Location
      rec("Document Type") = Me.DocumentType
      rec("Number of Pages") = Me.NumberofPages
      rec("Date Received") = Me.DateReceived
      rec("Rev No") = Me.RevNo
      rec("Aircraft Number") = Me.AircraftNumber
      rec("Job Numbers") = Me.JobNumber
      rec("Work Pack Issue Number") = Me.WorkPackIssueNumber
      rec.Update
      
      Set rec = Nothing
      Set db = Nothing
      But I am a total novice when it comes to coding. It didn't work. I don't know if I am referencing the correct table in this bit of code:

      Code:
      Set rec = db.OpenRecordset("Select * from Document")
      Also the table that I am drawing some information from is the work pack register table and inside that some of the field names are kind of strange. One is named Work Package Number/ Quality Book I have a feeling that to try and use this with code may cause problems because of the special character. Is this correct? I can't change the titles because i am sure there are other databases and queries that run from this table. The fields aren't the same from one table to another. So for example Document number in the document table relates to Work Package Number/ Quality Book in the other table.

      If there is a way I can update the table in the "postback" (I don't know what this means) then that would probably be better but I have no idea how to do that.

      Other examples I found and were playing with were:
      Code:
      Private Sub Command24_Click()
      
      Dim db As DAO.Database
      Dim rst As DAO.Recordset
      Dim varTextData As String
      varTextData = txtBox
      Set db = CurrentDb
      Set rst = db.openRecordset("tblDocument", dbOpenDynaset)
      rst.AddNew
      rst!fldDocumentNumber = varTextData
      rst.update
      rst.Close
      db.Close
      Me!txtBox = ""
      
      End Sub
      But like I said I really don't know what I am doing. So any help is appreciated.

      I wanted to put a screen shot up of the form but can't see a way to do that. :)
      Last edited by Rabbit; Sep 28 '15, 01:34 AM. Reason: Please use [code] and [/code] tags when posting code or formatted data.

      Comment

      Working...