Solved

Programmatically synchronize listbox scrolling in access

Posted on 1998-03-30
18
830 Views
Last Modified: 2008-02-01
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.
0
Comment
Question by:FalconMaster
  • 7
  • 6
  • 3
  • +2
18 Comments
 
LVL 2

Expert Comment

by:Bangerter
Comment Utility
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
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
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
 
LVL 2

Expert Comment

by:marti
Comment Utility
Isn't there a property like VB's TopIndex?
0
 
LVL 5

Expert Comment

by:tstaddon
Comment Utility
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
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
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
 
LVL 5

Expert Comment

by:tstaddon
Comment Utility
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
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
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
 
LVL 5

Expert Comment

by:tstaddon
Comment Utility
I'll look it up and get back to you.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
Yes this helps, I will check it out.  Thank you.
0
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
nietod,

do you know which library to use for the send message function?
(i.e. user32.dll / kernel32.dll)
0
 
LVL 22

Accepted Solution

by:
nietod earned 150 total points
Comment Utility
It is in User32.  There are two forms.  SendMessageA and SendMessageW.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Use SendMessageA() if your program uses 8 bit ASCII characters.  The other if you use wide (16 bit) characters.  
0
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
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
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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
 
LVL 2

Author Comment

by:FalconMaster
Comment Utility
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
 
LVL 22

Expert Comment

by:nietod
Comment Utility
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
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…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

771 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

14 Experts available now in Live!

Get 1:1 Help Now