?
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
Medium Priority
?
964 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 1000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

801 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