creating custom function?

M

martinmike2

Hello,

I am trying to create a custom function for my application. I have
never done this before. What I am trying to do is:

on the click event of an unbound textbox I want to set the value to
"X". normally I would just do this in the sub for the control,
however my form is a checklist so i have many of these unbound
textboxes. Also, there are multiple forms with this functionality. I
ave tried running the following code:

Public Function SetNotNeeded(ctlToUpdate As Control)
If IsNull(ctlToUpdate) = True Then
ctlToUpdate.Value = "X"
Else
ctlToUpdate.Value = Null
End If
End Function

and in the control i run:

Private Sub Text57_Click()
SetNotNeeded (Text57)
End Sub


When i click in the box, i get the "Object Required" error.
 
D

Douglas J. Steele

It's a rather subtle issue.

You've declared SetNotNeeded to be a function, and functions are intended to
return a value. However, you're not assigning the result of a function to a
variable (yeah, I know your function doesn't actually return a value...)

Change how you're calling the function to either

Private Sub Text57_Click()
SetNotNeeded Text57
End Sub

or

Private Sub Text57_Click()
Call SetNotNeeded (Text57)
End Sub

Another alternative would be to set the Click property to
"=SetNotNeeded(Text0)" (without the quotes, but with the equal sign), rather
than the current [Event Procedure]. Doing this means that you wouldn't have
the Text57_Click sub.
 
M

martinmike2

It's a rather subtle issue.

You've declared SetNotNeeded to be a function, and functions are intendedto
return a value. However, you're not assigning the result of a function toa
variable (yeah, I know your function doesn't actually return a value...)

Change how you're calling the function to either

Private Sub Text57_Click()
  SetNotNeeded Text57
End Sub

or

Private Sub Text57_Click()
  Call SetNotNeeded (Text57)
End Sub

Another alternative would be to set the Click property to
"=SetNotNeeded(Text0)" (without the quotes, but with the equal sign), rather
than the current [Event Procedure]. Doing this means that you wouldn't have
the Text57_Click sub.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)




I am trying to create a custom function for my application.  I have
never done this before.  What I am trying to do is:
on the click event of an unbound textbox I want to set the value to
"X".  normally I would just do this in the sub for the control,
however my form is a checklist so i have many of these unbound
textboxes.  Also, there are multiple forms with this functionality.  I
ave tried running the following code:
Public Function SetNotNeeded(ctlToUpdate As Control)
If IsNull(ctlToUpdate) = True Then
   ctlToUpdate.Value = "X"
Else
   ctlToUpdate.Value = Null
End If
End Function
and in the control i run:
Private Sub Text57_Click()
SetNotNeeded (Text57)
End Sub
When i click in the box, i get the "Object Required" error.- Hide quoted text -

- Show quoted text -

worked like a champ, thank you David
 

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