Programmatically synchronize listbox scrolling in access

Hello,

I am attempting to synchronize two list boxes in an access form so that when I scroll down on one, the other scrolls down the same amount.  I have partially answered my question by learning how to make a listbox scroll using a windows api call.  Unfortuneatley I have been unable to figure out how to tell how far the first listbox has scrolled, nor am I aware of any event I could associate code w/ in this version of access(7.0)

I am willing to look at other ways of doing this(i.e. not using windows api) if there are any available.
LVL 2
FalconMasterAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BangerterCommented:
is it necessary to use 2 different list boxes in your form (im assuming your useing this in a form). you can have 2 columns in your list box, each displaying different fields of data. if you are wanting to populate 2 different fields with this procedure you can do this. build your first list box with 2 columns the first column contains the data that you want to fill this box, the second contains the data that you will fill in the second box (this second column is only there for the user to see what will be filled in the second box. it has nothing to due with populating that box. meaning, if you dont want to you dont even have to display the second column). create a recordset in the OnExit event of the first box. from that recordset you can, using VB, go through the recordset and have it locate the first box's data and then populate the second box with the appropriate data.

if you need help writing the code let me know and i will give a step by step explaination with the code you need.
0
FalconMasterAuthor Commented:
Bangerter,

It is possible for me to use the method that you mentioned, and I did in fact consider it before asking my question here.  Currently I am attempting to use the same dialog box in my program for two slightly different processes(there are actually 3 listboxes, and in one circumstance, I am importing data for the first two listboxes from one table, and in the other I am importing the data for the last 2 listboxes -- I know it sounds odd, but I am sure I will have other uses for this information- I have also considered the possibility of putting in 2 listboxes with one of them like the one you mentioned, and simply changing their properties to switch them around at run time, but I am still not satisfied with the way that looks and what I am trying to do with my data).  I also would like my user to be able to do a search based on either field, and I am attempting to create a display that is more pleasing to the eye.  If you(or anyone else) would like a more detailed description, and a general picture of my dialog box, you may e-mail me at Falcon.Master@usa.net

I think I have found another part of the answer to my original question, and maybe it will help someone help me.  I think the constant I need to use is EN_VSCROLL(I might be a little off here, I am writing this from memory).  I am not sure how to use EN_VSCROLL, however, or which function(if any) it would be used in.  I have ordered volume 3 and 4 of the Win32 programmers reference, and I hope to find the info I am looking for there, but if I can get an answer faster than the time it takes me to look it up, I would really appreciate it.  

Thank you,

Chris
0
martiCommented:
Isn't there a property like VB's TopIndex?
0
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

tstaddonCommented:
You could use an OnClick event to identify what position you are in one listbox, then instruct it to jump to the same postion in the other listbox.
0
FalconMasterAuthor Commented:
Marti,

Access 7.0 does not seem to support the top index property.

tstaddon

yes, I can use the onclick or mousedown event to tell if I am scrolling, but I do not know how to find what position I am in with scroll bar.(I am not sure how to return a value from the scroll bar telling me either how far I have scrolled down or up, what position the data is in inside the listbox, or where the thumb of the scroll bar is. I am sure I could make my program work w/ any of this information.)

I am still kind of new to this service.  Does anyone know if I am able to repost this question on Win32 programming.

PS - Bangerter, I hope my rejecting your answer did not harm your rating in any way.  It was a good answer, just not the one I was looking for.


0
tstaddonCommented:
The scrollbar button size is related to the number of items in the list, and its position is relative to the position in the list. You could theoretically identify the position of the button on one list box in percentage terms, and move the second one accordingly.
0
FalconMasterAuthor Commented:
tstaddon,

Do you know how I can find out the position of the thumb on the one list box?  As far as I can tell, VBA does not support the ability to get this information about the scroll bar on a list box.  I know that I can use the Win32 API to get this information, but right now I do not know enough about the API to know which function or constants I would use, nor do I know how to implement them in the vba environment(I know the basics of using a declare statement, but all the examples I have found so far have been written in C code, and I do not yet know how to translate)

All
Another thought I have been having lately is to add a list box ocx that has the topindex property.  At this point, I don't have such a list box available, nor am I sure exactly how I would need it set up to insert it into Access(remember I am using an older version of Access(v 7.0 = Access 95)

0
tstaddonCommented:
I'll look it up and get back to you.
0
nietodCommented:
I don't know anything about access, but I saw you question in the Windows section.

You can us the LB_GETTOPINDEX message to get index of the top item visible in a list box.  You can use the LB_SETTOPINDEX message to set the top item that is visible to a specified item.

0
nietodCommented:
To do this in C++ you would do

int TopItemIndex = SendMessage(MasterLisboxHandle,LB_GETTOPINDEX,0,0);

SendMessage(SlaveListBoxhandle,LB_SETTOPINDEX,,TopItemIndex,0);

Does this help?
0
FalconMasterAuthor Commented:
Yes this helps, I will check it out.  Thank you.
0
FalconMasterAuthor Commented:
nietod,

do you know which library to use for the send message function?
(i.e. user32.dll / kernel32.dll)
0
nietodCommented:
It is in User32.  There are two forms.  SendMessageA and SendMessageW.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
Use SendMessageA() if your program uses 8 bit ASCII characters.  The other if you use wide (16 bit) characters.  
0
FalconMasterAuthor Commented:
What a pain.  I think I am chasing my tail on this one.  Apparently VBA doesn't accept the hwnd property for anything other that forms or reports(not listboxes, textboxes etc.) without that, I can't tell windows what control to use the function on.

nietod, although it didn't work, and apparently won't, I think your answer was at least closest to the one I was looking for, and very helpful I might add.  
I'm going to give you a B, but because the answer couldn't work in this situation 100%  I will give a little info( as I understand it) as to how to set up a declaration in Visual basic for API calls, so that people spending their points on this question(probably assuming that the answer for this question worked) will at least get something.


Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

for info on how to declare the constants LB_GETTOPINDEX, and LB_SETTOPINDEX, you would look in Win32Api.txt
ex.    In your function you would declare the following.

Dim TopItemIndex As Long, MasterListBoxHandle As Long
Dim SlaveListBoxHandle As Long
Const LB_GETTOPINDEX = &H18E
Const LB_SETTOPINDEX = &H197

In Visual Basic, you should be able to get the handles for the Master and Slave ListBoxes by doing something like

SlaveListBoxHandle = lstBox0.hwnd
MasterListBoxHandle = lstBox1.hwnd

OnClick and OnMouseDown events do not seem to work with regards to the scroll bar in the listbox, so the GotFocus event would probably be the best event to attach any code to. It will be necessary to start a loop that checks the status of the topindex periodically with the DoEvents function.  Also, since Visual Basic(not VBA) will accept the TopIndex Property, it is probably not necessary to do an API call for this particular problem.  VBA does not seem to support the TopIndex property or the hwnd property for listboxes, so I am not sure if it is possible to perform this function using Access Basic.

Since I have not had a chance to test this one out, I am unable to give more info than this, so hopefully this will help out those reading this.


0
nietodCommented:
I'm back.  Might there be another way to get the lost box's hndle?  Say using the windows APIs?  Perhaps using GetWindow() or ChildWindowFromPoint().  
0
FalconMasterAuthor Commented:
You might have a point,  it didn't occur to me that I might be able to get that info from outside of Access.  I'll see what I can find out.  If you know what coding I would use to get that, please let me know.

Thank you
0
nietodCommented:
I don't know enough about your design and what you already know.  ChildWindowFromPoint() will require that you can get the location of the list box.  GetWindow() will allow you to get each of the child windows of the window containing the list box.  However, yoou will need some way to differentiate between the child windows so you can find the right one.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.