Solved

copy to clipboard all selected items from a listbox in access 2003 and paste them in a table that is opened in datasheet mode

Posted on 2009-04-01
2
924 Views
Last Modified: 2013-11-28
Hello , i would like to ask if theres a way to copy all items that i multiselect from a listbox in an access form and paste them in a table that is opened in datasheet mode.

Actually the problem is , that when i multiselect the items and copy them with ctrl-c to clipboad it only pastes tha last record of my bounded column of the listbox ...
i really need the record of the bounded column but not just the last one ...
I suppose that what i does is that it copies each record separately  and appends the clipboard with next record by deleting the previous one . the result is that it pastes only the last one . Thank you
0
Comment
Question by:Anisoropos
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 28

Accepted Solution

by:
TextReport earned 250 total points
ID: 24047968
The Copy will not work for you as you have discovered, you can process the selected values and either paste this or use those to add the new records to the table through code, I would recoment the latter.

The code below will get the first column value, usually the ID into a string, this string can be used in a IN Clause for your INSERT Statement as shown later in the example. This is a command button on the form and you will have to adapt the code to match your field names and control names.

Cheers, Andrew
Private Sub cmdGetID_s_Click()
Dim strList As String
Dim cnt As Long
 
    If Me.lstMyListBox.ItemsSelected.Count > 0 Then
       For cnt = 0 To Me.lstMyListBox.ItemsSelected.Count - 1
           ' use this line if ID is a Number
           strList = strList & ", " & Me.lstMyListBox.Column(0, Me.lstMyListBox.ItemsSelected(cnt))
           ' use this line if ID is text
           strList = strList & ", " & Chr(39) & Me.lstMyListBox.Column(0, Me.lstMyListBox.ItemsSelected(cnt)) * Chr(39)
       Next cnt
       If strList <> "" Then strList = Mid(strList, 3)
       MsgBox strList
       
       strSQL = "INSERT INTO MyTable" & vbCrLf & _
                "   (ID, Field1, Field2)" & vbCrLf & _
                " SELECT ID" & vbCrLf & _
                "      , Field1" & vbCrLf & _
                "      , Field2" & vbCrLf & _
                " FROM MyTable" & vbCrLf & _
                " WHERE ID IN (" & strList & ")" & vbCrLf
        CurrentDb.Execute strSQL, dbFailOnError
    End If
End Sub

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question