Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where in the Code?

Status
Not open for further replies.

CRBI

Technical User
Jul 9, 2008
9
US
I have two fields that change regularly and want to show a different image if Field1 and Field2 are =, <, or > when the values change. I have sucessfully written the code that will work if I take the form to and from design view by placing it in the Form_Current()... I have been unsuccessful in placing in After Update at the field and form level. Code below:

Private Sub Form_Current()

SC1.Visible = False
SR1.Visible = False
SL1.Visible = False
txtCCenter.Visible = False
txtECenter.Visible = False
txtCRight.Visible = False
txtERight.Visible = False
txtCLeft.Visible = False
txtELeft.Visible = False

If txtCBase.Value = txtEBase.Value Then
SC1.Visible = True
txtCCenter.Visible = True
txtECenter.Visible = True
ElseIf txtCBase.Value < txtEBase.Value Then
SR1.Visible = True
txtCRight.Visible = True
txtERight.Visible = True
ElseIf txtCBase.Value > txtEBase.Value Then
SL1.Visible = True
txtCLeft.Visible = True
txtELeft.Visible = True
End If

End Sub
 
What is the problem? Are you trying to set the visible property of a control that has focus? If so, shift the focus before running the code.
 
That may be my weakness. Where and when do you set focus?
 
At the beginning of that code would be best and to some other control, it can be useful to create a minute control for this purpose, otherwise, just choose a control that would not otherwise have focus, you will get an error if you try to give the current control focus.

Me.txtGetFocus.SetFocus

It would be best to put the code in a sub of its own that can be called from the various events.
 
If I place create a new sub, how do I sucessfully recall it? or do I
 
It would work something like this:

Code:
Private Sub Form_Current()
   SetControls
End Sub

Sub SetControls()
    Me.SomeControl.SetFocus

    SC1.Visible = False
    SR1.Visible = False
    SL1.Visible = False
    txtCCenter.Visible = False
    txtECenter.Visible = False
    txtCRight.Visible = False
    txtERight.Visible = False
    txtCLeft.Visible = False
    txtELeft.Visible = False
 
 If txtCBase.Value = txtEBase.Value Then
        SC1.Visible = True
        txtCCenter.Visible = True
        txtECenter.Visible = True
   ElseIf txtCBase.Value < txtEBase.Value Then
        SR1.Visible = True
        txtCRight.Visible = True
        txtERight.Visible = True
   ElseIf txtCBase.Value > txtEBase.Value Then
        SL1.Visible = True
        txtCLeft.Visible = True
        txtELeft.Visible = True
    End If

End Sub
 
No change noticed from before. If I take the from from design to form view, changes made will take effect.
 
Please say what your problem is, any error codes or messages for example?
 
No error codes. Just lack of change.
While in Design mode, txtCBase=5 and txtEBase=2
Once I go into form view, as it should,
SL1.Visible = True
txtCLeft.Visible = True
txtELeft.Visible = True
is displayed. If whlie in Form view txtCBase=5 and txtEBase=100, and the form refreshed,
SL1.Visible = True
txtCLeft.Visible = True
txtELeft.Visible = True
is still displayed.
 

Have you tried putting the same code in the AfterUpdate events of your text boxes?


Randy
 
In these two. txtCBase and txtEBase since they are the driving controls. yes.
 
How about:

Code:
Sub SetControls()
    sc1.Visible = (txtCBase.Value = txtEBase.Value)
    txtCCenter.Visible = (txtCBase.Value = txtEBase.Value)
    txtECenter.Visible = (txtCBase.Value = txtEBase.Value)

    sr1.Visible = (txtCBase.Value < txtEBase.Value)
    txtCright.Visible = (txtCBase.Value < txtEBase.Value)
    txtERight.Visible = (txtCBase.Value < txtEBase.Value)
    
    sl1.Visible = (txtCBase.Value > txtEBase.Value)
    txtCLeft.Visible = (txtCBase.Value > txtEBase.Value)
    txtELeft.Visible = (txtCBase.Value > txtEBase.Value)
    
    Me.Repaint
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top