Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2016
    Posts
    3

    Unanswered: Need help Updating a table from a form

    I am new to Access VBA and I am trying to update a table from a new form. We have a form where Users can report a defect in the database. That information saves fine. I am creating a form that will pull up defects that have a "Fixed" checkbox set to "No", which is also working.

    When I pull up a defect from a comboBox, I have a checkBox that I can click (indicating defect is fixed), then click the 'Save' button. The code I have saves changes to ID 1, which I'm assuming because I'm not referring the code to find the ID line associated with the defect I'm working on. Below is my code. If someone can tell me how to reference the "Defect" field so my update saves to the ID# associated with that defect, that would be swell.

    Code:
    Private Sub btnSaveRecord_Click()
        
        Set db = CurrentDb
        Set rs = db.OpenRecordset("tblDefectReport", dbOpenTable)
    '    rs.Index = "Defect"
    '    rs.Seek "=" .txtDefect
        
        With Form_frmDefectFixed
            rs.Edit
                rs![Fixed] = .chkFixed
                rs![DateFixed] = .txtDateFixed
                rs![RepairingUser] = .txtRepairingUser
            rs.Update
        End With
        rs.Close
        
    End Sub

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    So in your combo box have two columns
    One contains the primark key value and is usyally hidden
    The other (s) contain publiclly viewable data.
    Selecting the item in the clickbox then means you know the pk of the row to be updated.
    Then use that value to find the row in the recordset in your code
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    Sorry this is cackhanded
    If you already have column in the db, why not show that column on the form as a checkbox.
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •