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
586 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 37

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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 …

739 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