• Changing table values with code (Acc 97 sr2 on 95b)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Changing table values with code (Acc 97 sr2 on 95b)

    Author
    Topic
    #374125

    Ok, I admit, I use bits of code I only “sorta unnastand”.

    I have code (see below) that writes a record in a table, and I understand what it does.

    With rst
    .AddNew
    ![Job #] = cboChooseJob
    !DeptVal = optDept
    !Employee = lstEmployees.ItemData(varItm)
    !Hours = HrInput
    .Update
    End With

    What I want is code to change the value of .!Hours.

    Dim rst As Recordset
    Dim strRegistrationIDs As String
    Dim varItm As Variant
    If lstEmpAllocated.ItemsSelected.Count > 0 Then
    ‘ Build a list of the registrations to remove
    For Each varItm In lstEmpAllocated.ItemsSelected
    strRegistrationIDs = lstEmpAllocated.ItemData(varItm) ‘this value is the record ID for the chosen record. (tblJobAllocate.AllocID)
    Next

    ****** Code to go in here?*******

    With rst
    .Edit
    . !Hours = HrChanged
    .Update
    End With
    End If

    strRegistrationIDs tells me the record, how do I point to it correctly in order to change it.

    Viewing 0 reply threads
    Author
    Replies
    • #604114

      Sorry Allan, but I’m not clear on what you want to do. If you just want to search your recordset to find a record with a matching AllocID and then change a field in that record, you could do it like this:

      With rst
          'Go to the beginning of the recordset
          .MoveFirst
          'Find the first matching record (assuming it's a string value)
          .FindFirst "[AllocID]='" & strRegistrationIDs  & "'"
          'If NoMatch is true, there is no matching record so Not NoMatch
          'means you found one
          If Not .NoMatch Then
              .Edit
              !Hours = HrChanged 
              .Update 
          End If
      End With 
      • #604638

        Thankyou Charlotte, your coding was just what I was after. Sorry for not explaining myself more clearly.

        Didn’t know enough to write it but understand it completely now I see it.

    Viewing 0 reply threads
    Reply To: Changing table values with code (Acc 97 sr2 on 95b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: