Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

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

    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.
    "Heading for the deep end"

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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:

    <pre>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 </pre>

    Charlotte

  3. #3
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

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

    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.
    "Heading for the deep end"

Posting Permissions

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