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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

776 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