Bogus Error Message???

  • Thread starter Thread starter Mark A. Sam
  • Start date Start date
M

Mark A. Sam

Hello,

I set a function to the OnClick property of a command button:
=disableField()

The function looks like this:

******* Code Start ****
Public Sub disableField()

Dim ctl As Control
Set ctl = Form.ActiveControl

If (Form.Controls(Mid(ctl.Name, 8)).Enabled) = True Then
Form.Controls(Mid(ctl.Name, 8)).Enabled = False
Else
Form.Controls(Mid(ctl.Name, 8)).Enabled = True
End If

End Sub
******* Code End****

The function Enables or Disables a Textbox on the form. I get this error
message then I click the button:

The expression On Click you entered as the event property setting produced
the following error:

The expression you entered contains invalid syntax.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evalutiing the function, event or macro.

The function works fine and stepping though it doesn't result in errors
until after the End Sub statement when the above appears.

If I call the function from the Event Procedure, it works smootly without
error.

I don't wish to open the event procedure for every button I am using this
on, when I can more easily select the bottons and enter the function name on
the OnClick property.

Thanks for any help.

God Bless,

Mark A. Sam
 
Nick,

Yes, ctl is set to it with the line:

Set ctl = Form.ActiveControl

The purpose is to enable/disable a particular control on the form. The name
of the button corresponds to the control name being enabled/disabled, for
example, the Button name would be [disableDateLoading] which disables and
enables control, [DateLoading]

I don't see that as in issue though. The function works in the event
procedure. I have this issue a couple days ago, and can't recall how I
resolved it. I think I repaired and compacted the database, but that didn't
work this time. I also applied the function to another button and got that
same error.

God Bless,

Mark


Nick Coe (UK) said:
Won't the command button be the active control when you
click it?

--
Nick Coe (UK)
www.alphacos.co.uk

---

Mark A. Sam said:
Hello,

I set a function to the OnClick property of a command button:
=disableField()

The function looks like this:

******* Code Start ****
Public Sub disableField()

Dim ctl As Control
Set ctl = Form.ActiveControl

If (Form.Controls(Mid(ctl.Name, 8)).Enabled) = True Then
Form.Controls(Mid(ctl.Name, 8)).Enabled = False
Else
Form.Controls(Mid(ctl.Name, 8)).Enabled = True
End If

End Sub
******* Code End****

The function Enables or Disables a Textbox on the form. I get this error
message then I click the button:

The expression On Click you entered as the event property setting produced
the following error:

The expression you entered contains invalid syntax.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evalutiing the function, event or macro.

The function works fine and stepping though it doesn't result in errors
until after the End Sub statement when the above appears.

If I call the function from the Event Procedure, it works smootly without
error.

I don't wish to open the event procedure for every button I am using this
on, when I can more easily select the bottons and enter the function name on
the OnClick property.

Thanks for any help.

God Bless,

Mark A. Sam
 
Mark A. Sam said:
Hello,

I set a function to the OnClick property of a command button:
=disableField()

The function looks like this:

******* Code Start ****
Public Sub disableField()

Dim ctl As Control
Set ctl = Form.ActiveControl

If (Form.Controls(Mid(ctl.Name, 8)).Enabled) = True Then
Form.Controls(Mid(ctl.Name, 8)).Enabled = False
Else
Form.Controls(Mid(ctl.Name, 8)).Enabled = True
End If

End Sub
******* Code End****

The function Enables or Disables a Textbox on the form. I get this
error message then I click the button:

The expression On Click you entered as the event property setting
produced the following error:

The expression you entered contains invalid syntax.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evalutiing the function, event or macro.

The function works fine and stepping though it doesn't result in
errors until after the End Sub statement when the above appears.

If I call the function from the Event Procedure, it works smootly
without error.

I don't wish to open the event procedure for every button I am using
this on, when I can more easily select the bottons and enter the
function name on the OnClick property.

The procedure you posted is defined as a Sub. It must be a Function,
not a Sub, for this to work. That's probably your main problem.

Also, where is this function defined? It would have to be defined in
the form's module, not in a public module, for the reference to "Form"
to work as written.
 
I place the functons in the Event Procedures. It works and no need to
pursue this any longer.

God Bless,

Mark A. Sam
 
Mark
add, after Dim ctl As Control:
Dim frm As Form
Set frm = Screen.ActiveForm


Damon

Mark A. Sam said:
Nick,

Yes, ctl is set to it with the line:

Set ctl = Form.ActiveControl

The purpose is to enable/disable a particular control on the form. The name
of the button corresponds to the control name being enabled/disabled, for
example, the Button name would be [disableDateLoading] which disables and
enables control, [DateLoading]

I don't see that as in issue though. The function works in the event
procedure. I have this issue a couple days ago, and can't recall how I
resolved it. I think I repaired and compacted the database, but that didn't
work this time. I also applied the function to another button and got that
same error.

God Bless,

Mark


Nick Coe (UK) said:
Won't the command button be the active control when you
click it?

--
Nick Coe (UK)
www.alphacos.co.uk

---

Mark A. Sam said:
Hello,

I set a function to the OnClick property of a command button:
=disableField()

The function looks like this:

******* Code Start ****
Public Sub disableField()

Dim ctl As Control
Set ctl = Form.ActiveControl

If (Form.Controls(Mid(ctl.Name, 8)).Enabled) = True Then
Form.Controls(Mid(ctl.Name, 8)).Enabled = False
Else
Form.Controls(Mid(ctl.Name, 8)).Enabled = True
End If

End Sub
******* Code End****

The function Enables or Disables a Textbox on the form. I get this error
message then I click the button:

The expression On Click you entered as the event property setting produced
the following error:

The expression you entered contains invalid syntax.
*The expression may not result in the name of a macro, the name of a
user-defined function, or [Event Procedure].
*There may have been an error evalutiing the function, event or macro.

The function works fine and stepping though it doesn't result in errors
until after the End Sub statement when the above appears.

If I call the function from the Event Procedure, it works smootly without
error.

I don't wish to open the event procedure for every button I am using this
on, when I can more easily select the bottons and enter the function name on
the OnClick property.

Thanks for any help.

God Bless,

Mark A. Sam
 
Dick,

That was the problem and also how I corrected it last time.
Thanks and God Bless,

Mark
 
Back
Top