How to properly use oleobjects and recordsets? - excel

I've some issues with OLEObjects and recordsets...
I create some controls on the fly in my code.
I prepare them, I fill them, and then I use the data collected from them to run a query on an AS400 (adodb).
When I get the data back I've this issue :
my oleobjects on top of the worksheet start acting weird: they seem normal, but when I click on one of them, the Left property seems to change. While holding the mouse button down I see the control twice, once where it should be, and at another position offset to the right (let's call it the buggy version). If my pointer leaves the control it returns to its normal position.
The globality of the control reacts to my mouse click for offsetting the control to the right and showing its "Buggy version", but the normal behaviour (Click is the only event I manage) only happens if I click on the Buggy Version... Each time I run the query the buggy controls are more and more offset to the right.
Here are some pictures :
Start: all is ok
First query: behaviour after the first run when I click on the left part of the button:
Second query: same, but the offset is greater:
When I don't click on the controls they are like in the first picture.
This affects all my controls except the first 3 which are at left = 0
I hope I was clear and that someone has an idea about what is happening.

Related

VBA Listbox not updating to reflect new source list when called from itself

Edit:
Playing around further, it seems that you can't assign a new array to a listbox via the .list=somelist approach when the assignment happens in response to a click on the listbox itself. Or rather, you can assign the list, but it simply won't visually populate the listbox...although Excel seems to think it's there.
The .additem or .removeitem methods do however result in a visual change when called from a listbox click, which means you have to build your new array up that way I guess. How tedious.
You can however feed a listbox an entirely new array using the .list=somelist approach via a CommandButton-initiated action. But the user has to obviously click a button to do this. Which in my case below defeats the purpose.
Edit Over.
I'm designing a UserForm to help filter PivotTables. It's a cross between the existing Pivot Filter functionality and a Slicer. Here's what you see if you double-click on a PivotField header:
Note the Search field at the top, and the three buttons immediately below that search field. If you type something into that field, then instead of displaying everything that's currently filtered, you instead get a list of any matches, and you can then apply those search results to the underlying PivotTable via those three CommandButtons. The first cb simply filters the PivotTable to reflect the search, and the other two let you add or remove any search result from an existing filter.
I want to do away with those three command buttons, and instead (in the event that a search is performed) simply list those three options at the top of the ListBox above any search results returned. Clicking on those three options will then trigger the exact same code as currently triggered by the Command Button.
Here's how that looks currently if I actually type something in that Search box (Note I haven't yet removed the three command buttons this does away with from that Search frame):
I've added a simple bit of code to the lbResults_Change() event handler that checks if a user clicks any of those first three options. All that code does is trigger the exact same routines as would be triggered if they'd simply clicked on the actual command buttons themselves:
For i = 0 To 4
If Me.lbResults.Selected(i) Then Exit For
Next i
Select Case i
Case 0: cmdApplySearch_Click
Case 1: cmdAddToFilter_Click
Case 2: cmdSubtractFromFilter_Click
Case 3: Me.lbResults.Selected(3) = False
End Select
Here' the problem: The listbox gets updated just fine if I click on those command buttons, as you can see from the below. The Pivot has been filtered accordingly, and those contextual search options have been removed from the top of the listbox (and the search field cleared):
But the listbox does NOT get updated if the exact same routine is triggered from a click on one of those top three options in listbox itself:
As you can see from the above screenshot, it still shows those three options at the top, even though they are NOT in the array that I assigned to the listbox, as evidenced by the screenshot below:
But as you could see from the earlier screenshot, it shows 7 items in the ListBox instead of the three there actually are. But there are indeed just three items that should be showing in that list box:
? .ListCount
3
? .List(0)
263213: ICT Systems Test Engineer
? .List(1)
263299: ICT Support and Test Engineers nec
? .List(2)
839313: Product Tester
Basically, as soon as I try to update what's in the listbox via a click on the listbox itself, I can't update it.
It doesn't seem to matter if I set focus to something other than the listbox before the filtering code executes, and I've even tried completely clearing the Listbox with .clear. It just doesn't clear, until I manually click on one of those command buttons again.
Anyone have any pointers?
Ah, what an idiot I am for overlooking the painfully obvious solution. The ListBox list happily redraws in response to any event other than the ListBox_Click event, right? So all I needed to do was to use the ListBox_Click event to determine what got clicked (as I currently do), and then use the ListBox_MouseUp event to trigger the actual updating of the ListBox list. Works a treat.
Hopefully this post will save someone else two days of pain in the future. Probably me.

Radio buttons stop and start working depending on where they are on page

I'm having a strange problem.
I have 3 worksheets that have 2 sets of radio buttons at the bottom of each sheet. On the first sheet, these radio buttons work fine. On the 2nd and 3rd sheet, the radio buttons on the bottom-middle of the page work, but the ones on the bottom-left side of the page do not. When I hover over them the cursor changes appropriately, but when I click on them they just flicker and the button does not fill in.
When I tried remaking the buttons, I found that if the buttons are situated in the middle or right side of the sheet, they work fine, but if I move them over to the left side of the sheet they stop working. It does not seem to be any particular cell line that breaks them (it appears that they consistently stop working in the middle of the M column). When I move them back to the right side of the page, they work again. If I have one button from a particular GroupName filled and move it over to the left, it remains filled and if I click on different button from the GroupName that is situated on the right, the button on the right fills in properly and the button on the left clears properly...I just can't click the button on the left to refill it.
I've tried copying the radio buttons directly from the first sheet (whose buttons are working properly), but that didn't work. I have also copied the formats from the first sheet onto the second sheet, thinking maybe the format of the cells was breaking the radio buttons in some way, but that didn't work either.
Has anyone heard of anything like this happening?
EDIT: I tried putting in a different ActiveX Control (a text box) and it too stops working when it is moved to the left side of the page.

Combobox not displaying the data items

I have been trying to add Data items for my combobox in the DialogWindow of my mfc project, at design time by setting strings delimited by semi-colons for the Data property of this combobox.
But it just shows empty combobox at runtime. I tried using AddString() method of this combobox manually in the OnInitDialog() event of the DialogBox too. But that was also not working.
Tried creating a demo project again and when I added the combobox and put the value a;b in the Data property of it, it is showing up. But tried the same on my project and it is still showing the empty list in the new combobox! Tried to compare both project's code, like the header files and initialization's etc. Found that both are same. Other than some event declaration for the buttons and my custom c++ code in my project, the rest of the code is same as that of the newly created demo project!
Why in my project this combobox is showing an empty list of items? :(
EDIT:
Just noticed that the items are already in the list. But the dropdown is of small height and thus preventing the actual items from showing up! :(
Tried to look increasing the size of the combobox, but I couldn't find any property in the Property Window and dragging the corners of th combobox doesn't increases the height either! :(
Increase the size of the dropdown list like this, in the design window:
Click on the arrow on the right side of the combobox (highlighted in yellow on first pic). Then click and drag the bottom mid resize marker to increase the height (highlighted in the second pic).
This will increase the size of the dropdown list.
Otherwise when we try to click on the resize markers to increase the height, it would be disabled. So make sure you click on the arrow on the right side of the combobox first.

Bug with Excel form control - scrollbar keeps scrolling

I'm creating a dynamic chart using an Excel form control -- the scrollbar -- and the way this works is exactly as described on http://www.excelcharts.com/blog/animation-interaction-and-dynamic-excel-charts/ (towards the bottom). I have a chart of data, and a column called "Chart source" that just does an index match based on the scrollbar's linked number. When you click through the scrollbar, it updates the chart source column and thus the chart.
The problem I'm having is that when I click the scrollbar, it keeps scrolling all the way, to either the left or the right, instead of moving incrementally one by one. The number counts through 1 by 1, but it goes all the way as if I were continuously clicking the button. This behavior stops in its tracks if I click and then move the mouse out of the arrow area. I've tried messing with the form control's "incremental change" and "page change" options to no avail. Things that do work: I can click and drag the scrollbar itself to the place I want it. I can type a new number in the cell linked to the scrollbar, and the scrollbar will jump to the right position.
Does anyone have an idea of how to fix this bug?
EDIT: I figured out the problem. This is a bug in Excel. If you are in "Page Break Preview" mode instead of "Normal" mode, this behavior will happen. Switching back to "Normal" mode (the first of the three icons in the bottom right next to the zoom) fixes this behavior.
This problem occurs when calculations that result from the changed value that is controlled by the scroll bar, takes too long. Changing to Manual calculation mode resolves the problem (although of course is not necessarily desirable in all cases)...
(see http://www.pcreview.co.uk/forums/slider-bar-continues-increment-mouse-hovers-over-arrow-t3064239.html)
The same has been happening to me, but my excel sheet was in "normal" mode.I believe the original answer is correct. I noticed this happens when I press a combination of keys or my hand lightly brushes across bottom pf laptop. Very annoying. Finally I sit and wait for the scrolling to stop then click back to top of sheet.
Possible answer... I have the problem with one type of worksheet, but only when another worksheet with VBA code is open. A fix might be, in the first worksheet:
File\Options\Advanced\Formulas\un-check Enable Multi-Threaded Calculation
I figured out the problem. This is a bug in Excel. If you are in "Page Break Preview" mode instead of "Normal" mode, this behavior will happen. Switching back to "Normal" mode (the first of the three icons in the bottom right next to the zoom)

Can I make Excel scroll smoothly without using middle-click?

I must work with nightmare Excel files. (I didn't create them, I just have to work with them).
They were so big (more than 50 big columns and 100 big rows) then I must scroll up/down and use "<" and ">" buttons to scroll left and right. When I scroll around, Excel always jumps to the next column or row. This make me crazy!
Can I develop a plugin or add-in to make Excel just scroll smoothly, like web browsers do? If so, please give me some resource or just some keyword to learn how to do it.
Another tip: when you click on Scroll lock on your keyboard, this will change the way your arrows keys will work.
Instead of moving from cell to cell, it will move the screen.
Yet, as Issun said, you cannot change Excel and AFAIK, you cannot "split" a cell when scrolling.
Furthermore, you can also change the number of rows that will scroll in the Windows Control Panel.
I'm sorry to tell you but the snapping to the top of a cell when you scroll is a design choice by Microsoft that you simply cannot get around while working within Excel. You can middle click your mouse to enable smooth preview zoom with the mouse, but once you click the program, it will snap back.
Instead of looking for a plug-in, you should look for a different program to run the .xls files to work on them. Perhaps even something as simple as opening the document in Google docs might allow you to scroll normally.
That being said, if you are having the problem of the cells being so big that when you scroll down it skips over some cells, assign either a command button or keyboard shortcut to this macro:
Sub DownOne()
ActiveWindow.SmallScroll Down:=1
End Sub
I have used this on several occasions due to Excel skipping cells because of their size. The reason is that the mouse "single scroll down" is by default set to Down:=3
You might be able to map this macro to a mouse wheel scroll event, but I believe you need to add a .dll to use that event (ref: http://support.microsoft.com/kb/837910)
Click down on scroll wheel (middle) of mouse (remember not turn, but click down). This will produce unique four way arrow. Now drag mouse up or down (or even sideways, left or right) and you will get slow smooth scroll.
Well, this is an extremely old thread, but I was having the same problem today.
Try going into your Mouse Settings in Control Panel and set your Wheel to Scroll 1 line at at a time.. I have some rows that are merged, and it was frustrating the hell out of me how quickly it would scroll past them. Turns out, I had my Wheel set to scroll 3 lines at a time (default I think).
Took me forever to figure it out (felt like an idiot once I did).
Note - You'll want to go back and set it back to 3 lines when you're done in Excel because it makes it painfully slow to scroll in your web browser.
Old thread I know, but I found a work around (if this is a repeat suggestion, sorry). Leave Column A alone, with "normal" sized cells. You can hide this column if you don't want to see it. Put all your contents in the remaining columns as you normally would and merge the content over several rows. Since column A is normal sized, you will get "smooth scrolling".
I had the same problem until I upgraded by office from 2014 to 2017. Now I have office 2017 [version 15.33 (170409)] and I can scroll by pixels using Mouse as well as Laptop trackpad. I am using MacOS Sierra version 10 operating system.

Resources