Solved

Access 2013 Set Conditional format of multiple field in a form – use with a subform related to ID: 39845510

Posted on 2014-02-12
2
588 Views
Last Modified: 2014-02-12
I asked this question - Access 2013 Set Conditional format of multiple field in a form – use with a subform related to ID: 39845510 and got a great solution that works with my form.

As a related question, I'd like to enter the function into a module and make it available to any for or subform

Help with that would be appreciated.


Code from the 1st question response was :

Private Sub Form_Load()

For Each ctl In Me.Controls

      If ctl.ControlType = acTextBox Then

            ctl.OnGotFocus = "=ChangeColor('" & me.name & "', '" & ctl.Name & "'," & " True)"
            ctl.OnLostFocus = "=ChangeColor('" & me.name & "', '" & ctl.Name & "'," & " false)"

      End If
 Next

 End Sub
 
with this in a module

Function ChangeColor(frmName As String, ctlname As String, booFocus As Boolean)

    If booFocus = True Then
   
       Forms(frmName).Controls(ctlname).BackColor = vbGreen
             
    Else
   
        Forms(frmName).Controls(ctlname).BackColor = vbWhite
       
    End If
End Function
0
Comment
Question by:rogerdjr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 38

Accepted Solution

by:
PatHartman earned 500 total points
ID: 39854361
You need to create a standard module for the code.  it can't be in the class module of a form.

Public Sub SetColor(frm as Form)
For Each ctl In Me.Controls

      If ctl.ControlType = acTextBox Then

            ctl.OnGotFocus = "=ChangeColor('" & frm.name & "', '" & ctl.Name & "'," & " True)"
            ctl.OnLostFocus = "=ChangeColor('" & frm.name & "', '" & ctl.Name & "'," & " false)"

      End If
 Next
End Sub

Open in new window

Then the load event becomes
Private Sub Form_Load()
    Call SetColor(Me)
End Sub

Open in new window


All I did was to change the "Me" reference to "frm".  You have to send the form reference into the sub but once you do, you can access anything with frm. that you could with me.
0
 

Author Closing Comment

by:rogerdjr
ID: 39854646
Perfect - thnks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question