Results 1 to 2 of 2
  1. #1
    database_1 is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2020
    Posts
    34

    Looping an Update command

    Hello, I have a line of code that allows the user to update an already input training for a training database. Where the EMP_ID and TRNG_ID correlate, the TRNG_ID is replaced with a newly made one which has the new date attached to it. My problem is, many training dates need changed to the same date. Currently I have a combobox but I would like to move to a multi select box but I am unsure if I could loop it or not. I could always do a double click method but I wanted to try this and see if it was possible. Thank you.





    Set rst = CurrentDb.OpenRecordset("TRNG_TBL")
    With rst
    .AddNew
    .Fields("TRAINING") = Me.TXT_TR.Value
    .Fields("DATE") = Me.TXT_DATE.Value
    .Fields("SPCL_ID") = 2
    .Fields("POS_ID") = Me.COM_POS.Value
    .Update
    End With




    Dim set_id As Integer
    set_id = DMax("TRNG_ID", "TRNG_TBL", "SPCL_ID = '" & 2 & "'")


    Dim EMP_ID As Integer
    EMP_ID = Me.TXT_EMP.Column(2)


    Dim t_name As String
    t_name = DLast("[TRAINING]", "[TRNG_TBL]", "[TRNG_ID] = " & set_id & "")


    CurrentDb.Execute "UPDATE [EMP_TRNG_TBL] SET [TRNG_ID] = " & set_id & " WHERE [TRAINING] = '" & t_name & "' And [EMP_ID] = " & EMP_ID & ""

  2. #2
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    I don't fully understand your situation but you can loop through a multiselect listbox like so and test if an item is selected. If an item is selected you could run your query against each item, OR you could build a list of selected IDs in a string and run a single update query after the loop is finished.
    Code:
         Dim i As Integer
         For i = 0 To Me.LISTBOX.ListCount - 1
            If Me.LISTBOX.Selected(i) Then
                'Do something with the selected item
                Debug.Print Me.LISTBOX.ItemData(i)
            End If
        Next i

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Looping through table 1 to update table 2
    By Thompyt in forum Programming
    Replies: 3
    Last Post: 11-10-2016, 04:16 PM
  2. Replies: 3
    Last Post: 08-08-2016, 07:28 AM
  3. ADODB looping through and update help!
    By fluffyvampirekitten in forum Access
    Replies: 5
    Last Post: 01-11-2016, 10:33 AM
  4. Replies: 14
    Last Post: 05-07-2014, 05:11 PM
  5. Replies: 9
    Last Post: 01-31-2014, 12:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums