Monday, September 30, 2013

Objek.

Just when I was rejoicing about the simple solutions I have discovered, I'm facing a new problem: a bug Microsoft did not fix since 2003 (or probably earlier than that) with Multipage control, which shows wrong Page content.

The Multipage's Tab and all other Controls on the Userform are referring to the Page I wanted, say PageMe but the content dispayed in the Multipage is from another page, say PageYou. This happens after a Multipage_Change event procedure which tell the Multipage to return to PageMe if user changes to PageYou but the condition in a TextBox, say TextMsg on PageMe is still not met.

Say PageMe index is 0 and PageYou index is 1, and the Multipage name is MultipageUs, the simple code is something like this:

Private Sub MultipageUs_Change()
     If TextMsg = "#" Then MultipageUs.Value = 0
End Sub

Since I cannot disclose much information about my actual project here, the problem is basically similar to the ones found in the following links:

http://www.ozgrid.com/forum/showthread.php?t=165876

http://dailydoseofexcel.com/archives/2004/07/20/bug-multipage-controls-on-2003/

I've tried the workarounds suggested using Application.OnTime, the Value = Value - 1 etc, but still the problem persist.

My only option here is to disable something that I really do not want to disable.

Although I'm not sure if there if there is anyone who read my post, I'm going to take my chances: Do you have any other possible solution or a workaround? If you have, please tell me and I will treat you with Sate Jalee if you ever come to Kerteh.

Thanks.

Sunday, September 29, 2013

Nakharom.

It is one of those "duh" situation.

I am working on a VBA project which links Excel with SAP FrontEnd.

Bla bla bla... I discovered a problem whereby I can't remove focus from a Userform Button after clicking on a Msgbox prompt or when another sub-Userform is loaded.

Yes, I tried using SetFocus to another Control, putting the whole object reference i.e. Userform1.Button1.SetFocus, setting a dirty Boolean to terminate, setting another event etc... yet it still didn't work. No error was thrown by VBA though, but there was a problem since there is another procedure to disable the darn Button after pressing 'No' in the Msgbox prompt or cancelling the sub-Userform. Basically, in the scenario I was testing, I end up with a disabled Button which has focus. Weird and everything else stuck except for the Esc key.

After two sleepless nights trying to figure a workaround, I was still unable to solve this issue.

Yes, I googled too... that is the first thing anyone will do when stuck with a problem isn't it? Anyway, if someone has discovered the solution out there, it will probably end up in page 2 or 3 (or further down...)

Finally just now, I discovered the solution: a Control property which is rarely mentioned in VBA books: TakeFocusOnClick.

I set it to False and voila! Problem solved!

I also I discovered how to reactivate Excel window after SAP CreateSession on an active GuiSession object. 

I tried AppActivate and even an API call procedure which I don't even understand but Excel icon will only blinks on the taskbar. Excel did not actually open back and I still see the ugly SAP interface. 

Solution was using GuiMainWindow.Iconify method. It minimizes the SAP GUI window and I got what I wanted.

Ah, two simple solutions for problem I was having for days.

Puas.