How to do function, then procedure w/single OnClick

brucend75

New member
Local time
Today, 12:02
Joined
Feb 18, 2007
Messages
6
When I click on a command button, I want to 1) call a user-defined function, then 2) Run a procedure.

The function displays text on an unbound textbox. The procedure creates a 20 second timer.

I've tried to embed the procedure call in the function, but then nothing else on the form can be invoked until the timer has run out.

Same problem with creating a procedure for the command button that first runs the function then runs the procedure. Nothing else on the form can be invoked until the timer has run out.

I need to find a way with one OnClick to run the function, then the timer procedure, with my being able to -- after the procedure has begun but before it has finished -- press a command button that stops the timer procedure in mid-process.

I have successfully clicked the command button that stops the timer, but only when I simply start the timer by itself.

So how do I initiate both the function & the timer procedure with one OnClick without linking the two togther such that I can't initiate the stop-timer action?

Thanks very much in advance!
 
Code:
Public Sub CmdButton_OnClick()
     Call FunctionName
     Call Procedure_Name
End Sub

That's the logic. Now, you probably have it set up right, but you'll need to post your code to demonstrate your problem. Make sure you're using "DoEvents"
 
Thanks, Modest.

I'd tried that. I tried it again with exactly your code. Same problem. I couldn't click on the stop-timer button until the timer ran out. (the stop-timer button sets a public boolean to false; a check for that is in the loop in the timer code and breaks out of the loop to do a closedown/cleanup routine.) Again, the stop-timer works if the timer is started by itself.

Here is the code for the timer procedure:

Public Sub Time()

Dim timeNow, startTime, secondNow, MtrPercent As Single


timeNow = Second(Now())
startTime = timeNow
secondNow = 0
timeIsRunning = True

Do While secondNow < 20

If timeIsRunning = False Then

GoTo resetTime:

End If

timeNow = Second(Now())

If timeNow < startTime Then

secondNow = (timeNow - startTime) + 60

Else

secondNow = timeNow - startTime

End If

MtrPercent = secondNow / 20

Forms![Main Screen].lblmeter.Width = CLng(Forms![Main Screen].lblbase.Width * MtrPercent)

Select Case MtrPercent

Case Is < 0.33

Forms![Main Screen].lblmeter.BackColor = 65280 'green

Case Is < 0.66

Forms![Main Screen].lblmeter.BackColor = 65535 'yellow

Case Else

Forms![Main Screen].lblmeter.BackColor = 255 'red

End Select

DoEvents

Loop

Exit Sub

resetTime:

secondNow = 0
Forms![Main Screen].lblmeter.Width = 0
Forms![Main Screen].lblmeter.BackColor = 0

End Sub

Thanks again, and hope you can help.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom