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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

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…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now