Private Function not working

G

Guest

My problem is that I cannot seem to get the following Private Function to
work. This function is triggered by running the following code in an After
Update of a combo box. This combo and all of the field referenced in the code
are in the same form.


Private Function UpdateTimeSeconds()


If Me.TaskID = 57 Then
If Me.chkOccursInFactory = True Then
Me.TimeSeconds = Me.txtJimBob * 0.1 * 60
Else
Me.TimeSeconds = Null
End If
End If

End Function

The result of this code is negative the code does not perform the
calculation and paste it in the TimeSeconds field nor does it change
TimeSeconds to Null. The fields are editable and not locked. And I have tried
this code in many different Event locations but no action seems to take
place. Any ideas?

Thanks,

Dennis
 
T

tina

well, the code only runs when the value of TaskID is 57. have you put a
"break" on the code and stepped through it to check the values being read
from the controls, and see whether the "57" value is captured appropriately?

hth
 
G

Guest

Tina,

I cannot get the code to fire nor can I get the break to respond so I can
step through the code. I have changed the code's location to the Lost Focus
of chkOccursInFactory check box's Event and have also tryed the Click Event
to no avail. Below is the code I am using. To make certain record "57" is
identified, I click the checkbox of record "57".

Private Sub TaskID_LostFocus()

If Me.TaskID = 57 And Me.chkOccursInFactory = True Then

Me.TimeSeconds = Me.txtJimBob * 0.1 * 60
Else
Me.TimeSeconds = "0"
End If
End Sub
 
T

tina

well, if none of the events are firing, then it sounds like you have a
bigger problem than a single custom function. and in fact, if the code never
runs then you don't know if it works or not. the AfterUpdate control event
only runs when data in a control is changed, so that might be why that event
doesn't fire - but if you're moving out of the control, then the LostFocus
event should run...well, unless you're moving out of the control by moving
from a mainform to a subform, or vice versa.

btw, you posted the function code, but you never posted the event code that
calls the function. we can take a look and see if you're calling the
function correctly. also, did you try putting the code break in the
*calling* procedure, or in the function? make sure you try breaking in the
calling procedure - that's the only way to be sure the control event is
firing.

hth
 
G

Guest

Thanks Tina,

The anwser to my question is =UpdateTimeSeconds() in the after update of the
chkOccursInFactory check box. Once the user checks the check box, the
following code fires:

Private Function UpdateTimeSeconds()

If cboQuota.ListIndex < 0 Then Exit Function

If Me.TaskID = 57 And Me.chkOccursInFactory = True And
cboQuota.Column(0, cboQuota.ListIndex) = "Optical" Then
Me.TimeSeconds = Me.txtJimBob * 0.1 * 60
Else
Me.TimeSeconds = 60
End If

End Function

(A friend of mine fixed it) It works now.
 

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