Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing Immediate Window Programmatically

Status
Not open for further replies.

Steve101

Programmer
Mar 29, 2002
1,473
AU
I am trying to clear the program window programmatically; in some cases this will help me with my interactive debugging.

The code below works fine, and I suppose that I could assign it to a function key and use it as is:
Code:
Function ClearImmediateArea()
SendKeys "^g", True    'go to the immediate window
SendKeys "^a", True    'select all content
SendKeys "{del}"       'delete it
SendKeys "{f7}"        'go back to code window
End Function
The problem is that as soon as I add a line of code which writes to the debug window AFTER the call to the above function, it stops working; ie.
Code:
Function CallClearImmediateArea()
Debug.Print "Before"
ClearImmediateArea
End Function
works, but ...
Code:
Function CallClearImmediateArea()
Debug.Print "Before"
ClearImmediateArea
[red]Debug.Print "After"[/red]
End Function
does not. I've tried playing with the wait parameter on the Sendkeys command, but without success.

Can anyone figure?

If there's a system method to do the same thing, that would also of course suffice; though I'm really curious as to why this wont work. Even tried putting in a couple of timing delays between the lines, but all to no avail.

Any explanation would be appreciated,

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Have you tried to play with the Windows collection of the VBE object ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Thanks for that PH; was hoping that I could resolve this along the lines I was going, but maybe not.

I got a reference to vbe.Windows.Item("Immediate") but from here, no evident methods to clear the window.

Cheers

Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Perhaps playing with SetFocus before each SendKeys ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
set focus to what though? I am running the code directly from the module window; are you suggesting that if i put an interface in front of this, it might work; interesting, though it might defeat the aim of what i'm trying to do.
I have tried using docmd.SelectObject, but this did'nt help


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
vbe.Windows.Item("Immediate").SetFocus

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Dont think thats it; from a focus point of view, seems to behave itself ok; ^g and ^{f7} seem to do the trick here; did however try above, without success. has me baffled.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top