dialog box not getting the focus

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

dialog box not getting the focus

Post by stuck »

I have an outer loop that opens an Excel workbook and then asks the user for the number of tables to import from that workbook. Then there is an inner loop that gets the relevant number of tables and does stuff to each table. On the first pass through the outer loop the dialog that captures the number for the inner loop works as expected. It is presented and has the focus, so the user simply enters the number.

HOWEVER, second and subsequent times round the outer loop the dialog box is presented BUT when it appears, it does not have the focus, meaning the user has to first click on it before they can enter the relevant number of tables.

Any clues as to why this is happenning?

Ken
PS Yes this is Word VBA I'm talking about

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

Are you using InputBox, or Application.InputBox, or a userform?
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

An input box but I can't confirm if the code says Application.InputBox or just InputBox as I've gone home for the weekend :grin:

My guess is it will just say InputBox. Whatever the user types in goes to a variable that sets the upper limit on the loop that follows it.

Ken

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

I can't reproduce the problem in a quick test, so it most probably depends on the code that you execute inside the loops...
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

HansV wrote:...it most probably depends on the code...
And as that is 'Ken Kode®', it works but it's not pretty...

Thanks,

Ken

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

It's tempting to say something about Barbie code, but...
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

:laugh: Perhaps I might learn something here:
https://www.youtube.com/watch?v=PC-lGlExl34

Ken

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

:rofl:
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

As an aside, there's another 'unexpected side effect'. The 'Num Lock' on my keyboard gets turned off somewhere along the line...

Ken

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

That is definitely weird!
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

Not when you remember this is 'Ken Kode®' :grin:

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

Turns out it might not be so weird after all. This post on stackoverflow is talking about Access but the favoured reply says it's a bug in MS VBA. Plus, my Word VBA does use 'SendKeys' so when I get a chance that will be where I start looking:
https://stackoverflow.com/questions/259 ... ccess-form

Ken

User avatar
HansV
Administrator
Posts: 78412
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: dialog box not getting the focus

Post by HansV »

SendKeys has been reputedly buggy for many years now...
Best wishes,
Hans

User avatar
stuck
Panoramic Lounger
Posts: 8163
Joined: 25 Jan 2010, 09:09
Location: retirement

Re: dialog box not getting the focus

Post by stuck »

Yes, I'm aware of that but I couldn't find another way of getting at a particular tick box. There'll be a thread about it somewhere here. The stackoverflow thread though suggests a workaround so I'll try that.

Ken