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

Add controls to an app written entirely in a module?

Status
Not open for further replies.

jbradley

Programmer
Joined
Sep 7, 2001
Messages
248
Location
US
I have a small application that connects to an Access database using ADO and runs a query to update a field in one of the tables. The program has no user interface so I wrote it completely in Module1.bas, starting in Sub Main. I'm calling it from the Windows task scheduler on an hourly basis. I would like to add a timer control to make the program run the query on its own using a configurable delay, and maybe at some point rewrite it to run as a service using the NTSVC.OCX control.

Is there any way I can add a control to a module like this?
 
Could you create a form with a timer control, add interface to increment the interval, and add the code from the module to the form and execute it there?

I have great faith in fools; self-confidence my friends call it.
-Poe
 
I could. In fact, until the request came in to automate the program it had a user interface that displayed the number of records that needed updating and a command button to fire off the update. I was just hoping to not have to.
 
I could be wrong here, but if I were going to do the same thing here's what I would investigate. I believe that you can dynamically create an instance of a control such as a timer that doesn't have a visual component. To do so you would need to know how to reference the control, For that I believe you need to know it's classid. If you start poking around in the MSDN VB library for terms like "dynamically create control" and "classid" you may find what you need. That's where I'd start.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
The timer is sadly one of the controls that can't be hndled this way. On the other hand it isn´t that tricky to write your own version of the timer control - and a quick search in this forum should find my example of a Timer class that works just like the Timer control, but doesn´t need a form.

Having said that, just because you have a form does not mean you actually have to show it ...
 

SLEEP API

make the following declare:

Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)


call it thus:

Sleep 5000 ' causes 5 second delay

Hope this is what you need

---- Andy
 
Thanks for all the suggestions. The point about not actually needing to show the form is a good one. I sometimes get an idea stuck in my head to the exclusion of any alternatives.

Brad
 
Why couldn't you just use the Timer function Mod-ed by your delay interval in seconds? And remember to DoEvents.
 
Mainly becaue polling (and DoEvents, in my opinion) are best avoided where possible
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top