Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / ActiveX Controls / October 2005

Tip: Looking for answers? Try searching our database.

Retrieving selected data from ListView 6.0 control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Brian - 07 Oct 2005 17:26 GMT
I have added a ListView 6.0 activexcontrol to my form in Access.  I am
wondering how to basically take all of the selected items (from checkboxes)
and return them in a string separated by commas.  For
instance..."0575,0478,2028,2028".  I am also wondering how to have only one
bound column that adds to the string only the first column of data.  
Hopefully someone can help me out.  Please email me at brdgray@gmail.com if
you can assist.  Thank you.
Douglas J. Steele - 07 Oct 2005 18:56 GMT
AFAIK, you cannot bind a listview to data.

To get the details of what's been selected, try:

Dim intLoop As Integer
Dim strOutput As String

   For intLoop = 1 To Me.MyListview.ListItems.Count
       If Me.MyListview.ListItems(intLoop).Selected Then
           strOutput = strOutput & Me.MyListview.ListItems(intLoop) & ", "
       End If
   Next intLoop

   If Len(strOutput) > 0 Then
       strOutput = Left$(strOutput, Len(strOutput) - 2)
   End If

   MsgBox "You've selected " & vbCrLf & strOutput

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

>I have added a ListView 6.0 activexcontrol to my form in Access.  I am
> wondering how to basically take all of the selected items (from
[quoted text clipped - 6 lines]
> if
> you can assist.  Thank you.
Brian - 07 Oct 2005 20:08 GMT
Doug,

Thank you very much for your help.  Sorry to post to multiple boards, kind
of in a jam. A couple of things however...

When I select a checkbox, it basically just selects the
checkbox...therefore, when i check all of the checkboxes in the list, it only
returns the first number.

Also, the formatting of the column is off.  It removes the leading 0 to the
number.  Is it possible to gain this back in? Possibly another If statement...

I removed the LEN statement because it basically removes the last digits of
the last number selected from the listview.  It works fine without the
character count.

Thanks again for your help Doug, I really appreciate it!

Brian

> AFAIK, you cannot bind a listview to data.
>
[quoted text clipped - 25 lines]
> > if
> > you can assist.  Thank you.
Douglas J. Steele - 07 Oct 2005 21:29 GMT
See in-line

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> When I select a checkbox, it basically just selects the
> checkbox...therefore, when i check all of the checkboxes in the list, it
> only
> returns the first number.

Sorry about that. I'd never actually used the checkboxes, and couldn't get
them to turn on when I was testing previously!

I've got them working now, and from what I can tell, it's real ugly using
them!

First, you need to use API calls to determine whether or not a checkbox is
ticked.

Put the following declarations at the beginning of your module:

Private Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal Msg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETITEMSTATE As Long = (LVM_FIRST + 44)
Private Const LVIS_STATEIMAGEMASK As Long = &HF000

Your code for determining which are actually checked is:

       For intLoop = 0 To (Me.lvGeography.ListItems.Count - 1)
           lngReturn = SendMessage(Me.lvGeography.hWnd, _
              LVM_GETITEMSTATE, intLoop, ByVal LVIS_STATEIMAGEMASK)
           'when an item is checked, the LVM_GETITEMSTATE call
           'returns 8192 (&H2000&).
            If (lngReturn And &H2000&) Then
               strOutput = strOutput & Me.lvGeography.ListItems(intLoop +
1) & ", "
           End If
       Next intLoop

As I said, it's ugly, because the API numbers the rows in the listview from
0 to one less than Count, where VBA numbers them from 1 to Count.

> Also, the formatting of the column is off.  It removes the leading 0 to
> the
> number.  Is it possible to gain this back in? Possibly another If
> statement...

How are you populating the listbox? If these are actually numbers, you
should use the Format function to give you leading zeros. Alternatively, use
Format when concatenating your output:

      strOutput = strOutput & Format(Me.MyListview.ListItems(intLoop + 1),
"0000") & ", "

> I removed the LEN statement because it basically removes the last digits
> of
> the last number selected from the listview.  It works fine without the
> character count.

The LEN statement is to remove the comma from the end. If you look at my
example, I'm including ", " after each addition (that's a comma, followed by
a space). Therefore, I need to remove the last two characters in order to
not display comma-space at the end of the string. If you're using some other
concatenation character (such as comma-no space), you'll need to adjust your
trimming.

> Thanks again for your help Doug, I really appreciate it!
>
[quoted text clipped - 31 lines]
>> > if
>> > you can assist.  Thank you.
Brian - 10 Oct 2005 14:33 GMT
Thanks again doug for your help.  When I add your code to my module, the
checkboxes dissapear until they are clicked - then they are visible.  I'm
also guessing that the Listview called "lvgeography" is your specific
variable that I need to replace, correct?  Talk to you soon.

Brian

> See in-line
>
[quoted text clipped - 100 lines]
> >> > if
> >> > you can assist.  Thank you.
Douglas J. Steele - 10 Oct 2005 15:25 GMT
Sorry about that. Yes, replace lvGeography with whatever your listview
control is named.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Thanks again doug for your help.  When I add your code to my module, the
> checkboxes dissapear until they are clicked - then they are visible.  I'm
[quoted text clipped - 121 lines]
>> >> > if
>> >> > you can assist.  Thank you.
Brian - 10 Oct 2005 16:34 GMT
Did you happen to see the other problem with the check boxes are not visible
until they are double clicked? Is there a way to:
a) get single clicked
b) make them all visible on open

thanks.

> Sorry about that. Yes, replace lvGeography with whatever your listview
> control is named.
[quoted text clipped - 124 lines]
> >> >> > if
> >> >> > you can assist.  Thank you.
Douglas J. Steele - 10 Oct 2005 17:25 GMT
I don't have that problem, using either Access 97 or Access 2003.

Are you using mscomctl.ocx or comctl32.ocx? Which version? I'm using
mscomctl.ocx, version 6.1.95.45.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> Did you happen to see the other problem with the check boxes are not
> visible
[quoted text clipped - 150 lines]
>> >> >> > if
>> >> >> > you can assist.  Thank you.
Brian - 10 Oct 2005 17:45 GMT
I am using the same control - mscomctl.ocx - same version.  I tried putting
your code in again today to generate the checkboxes again, but it did not
work.  It does not recognize the SendMessage function as part of user32.

> I don't have that problem, using either Access 97 or Access 2003.
>
[quoted text clipped - 155 lines]
> >> >> >> > if
> >> >> >> > you can assist.  Thank you.
Brian - 10 Oct 2005 18:01 GMT
doug,

everything works great now doug...thanks for your help.  nevermind the last
posting, had a small glitch in the code

> I am using the same control - mscomctl.ocx - same version.  I tried putting
> your code in again today to generate the checkboxes again, but it did not
[quoted text clipped - 159 lines]
> > >> >> >> > if
> > >> >> >> > you can assist.  Thank you.
Brian - 10 Oct 2005 21:39 GMT
OK doug,

One more issue...Instead of having the format like: 0575,9384,3038,2028 ...
I need the format to be the following: ( WERKS = '0575' Or WERKS = '0384' Or
WERKS = '2038' )

There is a space after the "(" and before the ")"

Thanks in advance.

> doug,
>
[quoted text clipped - 164 lines]
> > > >> >> >> > if
> > > >> >> >> > you can assist.  Thank you.
Douglas J. Steele - 10 Oct 2005 23:52 GMT
Actually, you may be better off using (WERKS IN ('0575', '0384', '2038'))
rather than ( WERKS = '0575' Or WERKS = '0384' Or WERKS = '2038' ) if you're
going to have a large number of values: there's a limit to how long an SQL
statement can be.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> OK doug,
>
[quoted text clipped - 206 lines]
>> > > >> >> >> > if
>> > > >> >> >> > you can assist.  Thank you.
Brian - 11 Oct 2005 16:06 GMT
I'm not sure if you're familiar with connecting SAP to an Access database via
RFCs, but I am looking to pull in only data where the plant numbers (WERKS)
are selected.  It seems that I am only capable of pulling in 8 different
plant numbers before I get a SYSTEM_FAILURE.  Any ideas or thoughts?

> Actually, you may be better off using (WERKS IN ('0575', '0384', '2038'))
> rather than ( WERKS = '0575' Or WERKS = '0384' Or WERKS = '2038' ) if you're
[quoted text clipped - 211 lines]
> >> > > >> >> >> > if
> >> > > >> >> >> > you can assist.  Thank you.
Douglas J. Steele - 13 Oct 2005 22:09 GMT
Sorry, I have no idea what RFCs is. Sounds as though it may be the cause of
the problem, though.

Signature

Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

> I'm not sure if you're familiar with connecting SAP to an Access database
> via
[quoted text clipped - 238 lines]
>> >> > > >> >> >> > if
>> >> > > >> >> >> > you can assist.  Thank you.
Brian - 10 Oct 2005 23:28 GMT
Once again, i figured it out...thanks.

> I have added a ListView 6.0 activexcontrol to my form in Access.  I am
> wondering how to basically take all of the selected items (from checkboxes)
[quoted text clipped - 3 lines]
> Hopefully someone can help me out.  Please email me at brdgray@gmail.com if
> you can assist.  Thank you.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.