SendKeys to Run Query Analyzer Script (F5)

G

Guest

I have a button on a form that runs this code. It opens a script saved in a
folder in Query analyzer and hit's Enter when the connect to SQL Server
dialog box opens. I just can't seem to get it to start running the script.
i still have to hit F5 manually, but i wan't the script to start running
automatically.


Shell """C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe""" & _
"""N:ASSOC-3.sql""", vbNormalFocus

SendKeys "{Enter}", True

SendKeys "{F5}", True 'This doesn't seem to work.




--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
W

Wolfgang Kais

Hello Billy.

Billy said:
I have a button on a form that runs this code. It opens a script
saved in a folder in Query analyzer and hit's Enter when the connect
to SQL Server dialog box opens. I just can't seem to get it to start
running the script. i still have to hit F5 manually, but i wan't the
script to start running automatically.


Shell """C:\Program Files\Microsoft SQL Server\80\Tools\Binn\" & _
isqlw.exe"" ""N:ASSOC-3.sql""", vbNormalFocus

SendKeys "{Enter}", True

SendKeys "{F5}", True 'This doesn't seem to work.

Have you tried this:
 
G

Guest

I had a similar problem whereby a sendkeys command wasnt being carried out
all i did was repeat the Sendkeys call so

SendKeys "{F5}"
SendKeys "{F5}"

mine wasnt F5 though so probably not much use but may as well try!
 
G

Guest

Thanks for the idea. Sorry to say it didn't work.


--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
G

Guest

I tried this and it didn't work either.

SendKeys "{Enter} %Q E", True

the Enter works but nothing else.
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
G

Guest

This didn't work either

SendKeys "{Enter}%QE", True


I keep finding post where people say not to use SendKeys but I can't seem to
find any alternative that will do what I want.

--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
6

'69 Camaro

Hi, Billy.
This didn't work either

SendKeys "{Enter}%QE", True

How about the following?

SendKeys "{Enter}%QE", False
I keep finding post where people say not to use SendKeys but I can't seem
to
find any alternative that will do what I want.

Well, you shouldn't use SendKeys if you have an alternative. Precisely when
those keystrokes are eventually executed can be unpredictable. And for
future reference, SendKeys won't work in Vista with UAC turned on, so your
SendKeys code likely has a limited lifespan anyway.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
G

Guest

Sorry didn't work.

It's funny...the {ENTER} works I just can't seem to get F5 or Alt+Q+E to work.


--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
6

'69 Camaro

G

Guest

I tried taking out the quotes in the middle like you have here and just got
an error message.

They way I currently have it now, everthing works, except for the script
actually running in Query Analyzer. I still have to press F5 manually.
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
G

Guest

Maybe it has something to do with the screen focus. After the {ENTER}
command is executed the connect to sql server dialog box goes away and that's
where the code seems to stop. Do I somehow need to set the focus to Query
Analyzer before the next set of sendkeys to actually run the script?
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
G

Guest

I have another thought. Maybe the keys are being executed to quickly after
{ENTER} is executed.

Is there some sort of pause or sleep command that can cause a delay before
executing the following commands to run the script?
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 
6

'69 Camaro

Hi, Billy.
They way I currently have it now, everthing works, except for the script
actually running in Query Analyzer.

What you posted doesn't have a space between the executable file name and
the first command line argument, nor does it have a backslash after the
colon to signify the N:\ drive on the file path. That's what I attempted to
fix.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
6

'69 Camaro

Hi, Billy.
Maybe it has something to do with the screen focus. After the {ENTER}
command is executed the connect to sql server dialog box goes away and
that's
where the code seems to stop. Do I somehow need to set the focus to
Query
Analyzer before the next set of sendkeys to actually run the script?

Whatever application has the focus when the SendKeys commands are executed
is what will receive those commands. Therefore, if Query Analyzer doesn't
have the focus after the <ENTER> key, it doesn't receive the commands that
follow in SendKeys.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
6

'69 Camaro

Hi, Billy.
Is there some sort of pause or sleep command that can cause a delay before
executing the following commands to run the script?

Yes, but not within SendKeys. You would have to send the first volley of
SendKeys commands, then pause Access with VBA code, then set focus to Query
Analyzer and send the next volley of SendKeys, but that's a catch-22. If
Query Analyzer has the focus, Access doesn't have the focus to execute the
SendKeys line of code. When Access finally does have the focus and executes
the second SendKeys line of code, Access will receive those commands,
because it has the focus, not Query Analyzer.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
6

'69 Camaro

Hi, Billy.

I think I see the problem. Your Shell command doesn't list any of the
command line arguments besides the path and name of the input file, so
that's why it's not executing that script file.

Here's sample syntax for the command line to invoke Query Analyzer:

isqlw -S MyServer -d pubs -U sa –P password -i input_file -o output_file

Check the BOL for more information. Use isqlw -? for usage information.

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blogs: www.DataDevilDog.BlogSpot.com, www.DatabaseTips.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 
B

BillyRogers

I got this to work. (Note: Sleep is an API call)


Shell """C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe""" & _
"""N:\MyScript.sql""", vbNormalFocus
Sleep 500
SendKeys "{ENTER}", True
Sleep 500
SendKeys "{F5}", True
Sleep 500
--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top