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
916 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
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

840 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