Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8323123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:37:18+00:00 2026-06-08T23:37:18+00:00

I hope I can ask this right. I have a listbox on a form

  • 0

I hope I can ask this right.
I have a listbox on a form (access 2007) and have it set on “simple” so I can multi-select.
I am trying to update multiple columns in a table, based on the selections in the listbox. I have a few textboxes that I want to use as the information to update the table.
I have a loop that is only updating the first record in the table no matter how many items are selected.
I think I understand why it’s only updating the first record from my loop but am not sure

Dim db  As DAO.Database
Dim rs  As DAO.Recordset

Set db = CurrentDb()
Set rs = db.OpenRecordset("Table1", dbOpenDynaset)

Dim i As Variant

    For Each i In Listbox.ItemsSelected

    With rs
    .Edit

     !Col1 = Me.Textbox1
     !Col2 = Me.Textbox2
     !Col3 = Me.Textbox3

    .Update

    End With
    Next

I assume this is because I am not specifying the “where” in the loop I want my table updated, but I have no idea how to do this in this loop. I would have 3 columns in the listbox (at positions 1, 3 and 4) that all need to be included to specify which records in the table need to be updated. I have tried this as well using an sql query with DoCmd.RunSql but it seems impossible to change the focus of the ListIndex mid-query. Aplogies for my lack of knowledge I am pretty new to visual basic. Please Help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:37:19+00:00Added an answer on June 8, 2026 at 11:37 pm

    Simplified example how I would give it a try if I understood correctly:

    Sub MultiSelect_Listbox()
    
    Dim lCnt as Long
    dim lID as long     
    dim sSQL_Update as string    
    
    dim sText_1 as String
    dim sText_2 as String
    dim sText_3 as String
    
    dim bSuccess as Boolean
    
    sText_1 = me.txt_Textbox_1
    sText_2 = me.txt_Textbox_2
    sText_3 = me.txt_Textbox_3    
    
    With Me.lst_Listbox
        For lCnt = 1 To .ListCount
            If .Selected(lCnt) Then
                lID = .Column(0, lCnt - 1)
                'Example update for 1 column
                sSQL_Update = "UPDATE T_TABLE SET COL_TEXT_1 = '" & sText_1 & "' WHERE ID = " & lID & ";"
                bSuccess = Update_Statement(sSQL_Update)
            End If
        Next
    End With
    End Sub
    
    Public Function Update_Statement(sUpdate_Stmt) As Boolean
    
    Dim db                          As Database
    
    Set db = CurrentDb
    db.Execute (sUpdate_Stmt)
    Update_Statement = True
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanna make this rather simple to ask so I can hope for a
I hope I can explain this problem right, it's a bit confusing for me.
I hope someone can help me here. I'm having trouble loading this variable. Right
Couldn't find a better place to ask this so I hope you guys can
I hope this is the right place to ask. Here is my scenario for
I hope that this forum is the right place to ask this question! I
I hope I ask this question in a right place. Whatever we're all programmers.
hope someone can answer this. Here is some sample code. namespace std { #ifdef
hope someone can help. I have two tables: Users -UserID -UserName UsersType -UserTypeID -UserID
Hope someone can help i cant seem to get my head around this, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.