RE: Control Step Question

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Well I spoke too soon. That worked great until I closed the database. Since
the code it is calling requires it to have focus on the OnCurrent, it is
giving me an error about focus. So I changed the AfterUpdate code to send
the name of the field as well as its text. However, now I am getting Object
Required error. Since I am kinda new at this stuff, I need some help. I
know this is pretty basic, but I can't remember. How to I refer to a text
box so that I can set properties?

My code:

Public Sub ColorControl(FieldValue)
Dim ctrl As Control
Dim StatusNumber As Long
StatusNumber = FieldValue
Set ctrl = Screen.ActiveControl <-- this is what I bomb out on when
closing.

Changed the name to Public Sub ColorControl(FieldValue, FieldName)
..
..
..
Change Set ctrl to Set ctrl = FieldName after declaring it as a string and
that's where it says Object Required.

What am I doing wrong?

Thanks.


"OEB" wrote:

Thanks! That worked very well.

"Dennis" wrote:

well, you might simply try:

me.TheControlToChange.SetFocus
me.TheControlToChange.ForeColor = 0
me.TheControlToChange.BackColor = 0

and duplicate for all controls you want to change.



"OEB" wrote:

I am calling the after_update event for the text box in which I have it
change to a color depending on the number entered into it. What I need to do
is make sure the current record displays the appropriate colors. The code
for the after_update is:

Public Sub ColorControl(FieldValue)
Dim ctrl As Control
Dim StatusNumber As Long
StatusNumber = FieldValue
Set ctrl = Screen.ActiveControl

Select Case StatusNumber
Case "0"
ctrl.ForeColor = 0
ctrl.BackColor = 0
.
.
.
and for the OnCurrent event for the form I am calling:

Call [field name here]_AfterUpdate()

I guess it's the ColorControl routine that wants focus.

Any suggestions?

"Dennis" wrote:

What code (exactly) are you attempting to execute? I know that message well,
and it applies to certain activities, but not others.

"OEB" wrote:

Ok, I did that, but now it says "You can't reference a property or mehod for
a control unless the control has focus". What I am doing is calling the
after_update event for each field that is on the tab. How do I fix this?

"Dennis" wrote:

If it's a bound form, use the OnCurrent event.

"OEB" wrote:

I had seen some sample code a while ago - I don't know where it was - that
stepped through the controls on the page and formatted them. I have some
fields that I am formatting after update, but I find that they are not
showing the proper format when you go from record to record. I am thinking
that I need to step through the fields as I enter the page and reset the
formatting that way as well as after update. Any suggestions on how I can do
this? Also what is the property I need to put the Event Procedure on when
switching from tab to tab. Is it on Enter?

Thanks.
.



Relevant Pages

  • Re: Control Step Question
    ... Dim ctrl As Control ... Dim StatusNumber As Long ... Change Set ctrl to Set ctrl = FieldName after declaring it as a string and ... formatting that way as well as after update. ...
    (microsoft.public.access.formscoding)
  • Re: When is Invoke() Really Required?
    ... then it is safe to call that method. ... in the context of the calling thread, now if the calling thread does not ... > Invoke, BeginInvoke, EndInvoke and CreateGraphics. ... Does this apply for absolutely every method or property in a control ...
    (microsoft.public.dotnet.framework.windowsforms.controls)
  • Re: Pass Control as Argument
    ... The Call keyword, while optional, can help you avoid problems associated with those inconsistencies. ... because I really wasn't calling like I posted. ... > All of a suddent this code now passes the ctl argument as the value of> the ... > control) and the result is the same. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Pass Control as Argument
    ... No broken refs ... because I really wasn't calling like I posted. ... Function SelectAnItem(By Ref ctl as control, ... All of a suddent this code now passes the ctl argument as the value of the ...
    (microsoft.public.access.modulesdaovba)
  • Re: MFC ActiveX Control in VC++
    ... >> your implementation that still crashes, and the calling ... but I do not know what a "typelib class" is. ... > with MFC ActiveX control, and I do not want to drop the control on to th form or Dialog. ...
    (microsoft.public.vc.language)