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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Global code needed

Status
Not open for further replies.

JMM

Technical User
Feb 17, 2000
37
NZ
I want to change the font color of a field if a certain condition is met.

The condition is: if tbl1.field1 = true then tbl2.field2 fontcolor = red otherwise tbl2.field2 fontcolor is black.
This looks straight forward but tbl1.field1 is on a subform and tbl2.field2 is on a second subform - both on a main form.

I concluded that some sort of global function is necessary as tbl2.field2 appears on several different forms and subforms. I would like all instances of this field to change fontcolor if the condition is met.

Can anyone help?. Thanks.
 
Here is an example of a requery done in a subform that is in mulitple Forms. You need to fully qualify when doing certain things on the subform. Here is an example of doing a requery on the subform. The following code is in the subform. The subform is used by itself and in a main form -- the Main form is a tab control called "MotorDataEntry". First it does the Function FormToCheckFor() to see if a Main form(tab control) is loaded, if not then it knows it is being executed as a stand alone form. This is extracted from a program I have. The Function FormToCheckFor() I put in the Standard Module for the application. You may be able to make use of this function -- probably have to do some trial and error.

'--- Do requery depending on where invoked from -- code in subform
Dim FormToCheckFor As String, retMsg As String
FormToCheckFor = "MotorDataEntry" ' the main form
retMsg = SeeIfFormLoaded(FormToCheckFor)
If retMsg = "Yes" Then
Forms!MotorDataEntry!tabsubformEquipmentAttachments!CBAccessoryType.Requery
Else
CBAccessoryType.Requery
End If

--------------- Function to return where Form is loaded
Function SeeIfFormLoaded(FormToCheckFor) As String
Dim obj As AccessObject, dbs As Object
Set dbs = Application.CurrentProject
' Search for open AccessObject objects in AllForms collection.
For Each obj In dbs.AllForms
If obj.IsLoaded = True Then
'''Debug.Print obj.Name
If FormToCheckFor = obj.Name Then
SeeIfFormLoaded = "Yes"
Exit Function
End If
End If
Next obj
End Function
 
I created a form with 2 subforms
subForm1 named sub1
subForm2 named sub2
then in the OnCurrent Event of the Main Form, I checked the value of a textbox named txtName1 in Subform1. If it was true I set the ForeColor of a textbox named txtName2 in Subform2 to Red (255) and if it wasn't I set it to Black (0).
The process worked for me doing it this way.

Private Sub Form_Current()
If Me.sub1!txtName1 = true Then
Me.sub2![txtName2.ForeColor = 255
Else
Me.sub2![txtName2].ForeColor = 0
End If
End Sub
 
Do you not have a problem with the form using the ForeColor for all the filed objects?
 
Try using the FORMAT property of your control. You can set up to four different conditions for this property, which will be displayed only for the individual record.

For example, I use the following to set the text colour for a payment field for the four different possibilities.

$#,##0.00[Black];($#,##0.00)[Red];"Nil";"No Value Entered"[Blue]

This displays any positive amount as black, any negative amount as red, Nil as the default textcolour and "No Value Entered as blue text.

For more detail, check out the on-line help for "Format property".

Hope this helps.

Lightning
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top