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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to automate function launch after form has loaded?

Status
Not open for further replies.

DeGeneral

IS-IT--Management
Jul 4, 2003
12
GB
I need to automate a data processing application on a remote PC such that it can be launched from the Windows XP scheduler.

The program is written in VB6. It works fine when I run it manually - but I need to automate it. I have tried running the data processing code from "form_load" but it won't run. I think this is because it is linked to several databases and these need to load before the application can run. I have tried writing another program to open the first program and use "SendKeys" function to press the required button. However, "SendKeys" won't work unless I am logged on through the Remote Desktop Connection.

I either need to 1) fully automate the code so that no keypress is necessary or to 2) find a way to automate the "SendKeys" function when I am not logged on remotely.

Can anybody suggest a way that I might get this to work?

DeGeneral
 
What do you mean by "load the databases"? Setting up an ADO connection to the database?
I see no reason a function would work from a click/keypress event but not work on form_load. If the function is making a database call, then it either needs to open the connection to it inside the function, or you need to call the sub or function that does that first.
Are you using a "User DSN" maybe? Since those will vary by the user that's logged on, it could cause database access problems if you are not logged in. If so, switch to using a System DSN, or even a hardcoded connection string (although that could cause problems later if the SQL name/pass is to change).
 
I am using a "Data" object (from the toolbox). That makes it a DAO object I think. Can that be set inside the function? If so, how?

 
Have you considered implementing command parameters when you start the program from the scheduler?

If you start it locally (i.e. double-click the icon) then it runs normally but you could have the scheduler run it with something like

C:\SomePath\myEXE.EXE "Automatic"

The Command$ parameter will then return the value "Automatic" and you can use that to run the code that you want without clicking buttons. I would avoid displaying a form at all if you are running it in "Automatic" mode. Just start the program from Sub Main and display the form only if Command$ is blank.

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
I find that my recordsets contain no data when I try running that data processing code directly from form_load. However, when I call the same function by pressing a CommandButton, the recordsets have data. This leads me to conclude that, for some reason, the form needs to complete loading before the data processing can begin. Would Command$ get around this? I have never used Command$, do you know where I could get some sample code that would show me how to use it?
 
You can reference it just as you would a variable e.g

If Command$ = "Automatic" Then

It does sound though that some setup is required during, or possibly after, the Form_Load before the full database access is possible. It may be that some additional processing is happening in the Click-Event that needs to be there before everything runs properly.

[small]No! No! You're not thinking ... you're only being logical.
- Neils Bohr[/small]
 
Try using Form_Activate instead of Form_Load. The controls aren't activated in Form_Load.

-David
2006 Microsoft Most Valueable Professional (MVP)
2006 Dell Certified System Professional (CSP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top