How to change the value from a control property ?

  • Thread starter javiernews via AccessMonster.com
  • Start date
J

javiernews via AccessMonster.com

Hi,
I need to change the value from a control property (Not the Form property).

For example I have to change the value of control property of the control
button on the event "On Click"

For Each objFrm In accAppNew.CurrentProject.AllForms

strDocForm = objFrm.Name
accAppNew.DoCmd.OpenForm strDocForm, acDesign, , , , acHidden
Set objFrm = accAppNew.Forms(strDocForm)

For Each objCtr In accAppNew.Forms(strDocForm).Controls
If objCtr.ControlType = acCommandButton Then
For Each objPrp In accAppNew.Forms(strDocForm).
Properties
If objPrp.Name = "OnClick" Then
If Len(objPrp.Value) > 0 Then
objPrp.Value = Replace(objPrp.Value,
"Search Value", "New Value") '<<<< IN THIS LINE IS THE PROBLEM
End If
End If
Next objPrp
End If

Next objCtr
accAppNew.DoCmd.Close acForm, strDocForm, acSaveYes
Next objFrm

I repeat I can change the Form property,........ but Not the Control property
of the command button
Any help will aprecite.
 
M

Marshall Barton

javiernews said:
I need to change the value from a control property (Not the Form property).

For example I have to change the value of control property of the control
button on the event "On Click"

For Each objFrm In accAppNew.CurrentProject.AllForms

strDocForm = objFrm.Name
accAppNew.DoCmd.OpenForm strDocForm, acDesign, , , , acHidden
Set objFrm = accAppNew.Forms(strDocForm)

For Each objCtr In accAppNew.Forms(strDocForm).Controls
If objCtr.ControlType = acCommandButton Then
For Each objPrp In accAppNew.Forms(strDocForm).
Properties
If objPrp.Name = "OnClick" Then
If Len(objPrp.Value) > 0 Then
objPrp.Value = Replace(objPrp.Value,
"Search Value", "New Value") '<<<< IN THIS LINE IS THE PROBLEM
End If
End If
Next objPrp
End If

Next objCtr
accAppNew.DoCmd.Close acForm, strDocForm, acSaveYes
Next objFrm

I repeat I can change the Form property,........ but Not the Control property
of the command button


Are you sure that the form has a macro named "New Value"?

Your code refers to the form properties, not the control
properties. Try:


For Each objCtr In objFrm.Controls
If objCtr.ControlType = acCommandButton Then
If Len(objCtr.OnClick) > 0 Then
objCtr.OnClick = Replace(objCtr.OnClick, ...
 
J

javiernews via AccessMonster.com

Thank you Marshall for this lines

For Each objCtr In objFrm.Controls
If objCtr.ControlType = acCommandButton Then
If Len(objCtr.OnClick) > 0 Then
objCtr.OnClick = Replace(objCtr.OnClick, ...



This is good idea:
For Each objCtr In objFrm.Controls

But third & fourth line it did Not worked....
If Len(objCtr.OnClick) > 0 Then
objCtr.OnClick = Replace(objCtr.OnClick, ...

So I tryed thought PROPERTIES like this and it worked fine:
If Len(objCtr.Properties("OnClick").Value) > 0 Then
objCtr.Properties("OnClick").Value = Replace(objCtr.Properties("OnClick").
Value,......

The macro named "New Value" it was a sample only.

Thank any way for your support.
 

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