473,382 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Form Conditional Formatting Re-evaluation

I have a form for the SalesLead table that has a disabled and locked text box that displays a SuggestedClientName. I use conditional formatting to shade red any suggested ClientName (primary key) values that have no matching row in the Clients table (a different table from the record souce of the form). The expression counts the number of matching rows in the Clients table that match the SuggestedClientName value and then subtracts 1. If there is a matching entry, the expression returns 0, i.e. False. If there is no matching entry, the expression returns -1, i.e. True. Since ClientName is the primary key of Clients, the only possible results of the expression are 0 and -1.

Here is the expression:
Expand|Select|Wrap|Line Numbers
  1. DCount("ClientName","Clients","ClientName=[SuggestedClientName]")-1.
So far, so good. Works great when I load the form.

One way to handle this discrepancy is for the user to pull up the Clients form and add the new ClientName value. After adding the SuggestedClientName to the Clients table, the user returns to the SalesLead form. I want the conditional formatting to re-evaluate the SuggestedClientName text box in the form when the focus is returned to the SalesLead form.

This is where my problem lies.

No matter what I try, I have to close the form and re-open it to re-evaluate the conditional formtting. I tried adding the following VBA code to the form's On Got Focus event.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_GotFocus()
  2. Forms![SalesLead].[SuggestedClientName].Refresh
  3. End Sub
I also tried Requery and Recalc. No luck.

Do I have the wrong event? Do I have the wrong code? Does the disabled and/or locked settings have anything to do with my problems?

HELP!!!
Aug 27 '11 #1
3 2868
while waiting for a reply, i kept searching forums. and i found the solution. turns out i had the wrong event. i added the same code to the form's On Activate event. worked like a charm!

whew!

still not sure why On Got Focus did not work. maybe somebody can explain the difference between these two events. thanks in advance!
Aug 27 '11 #2
p.s. also had to change the code to requery. refresh and recalc kicked out as invalid.
Aug 27 '11 #3
NeoPa
32,556 Expert Mod 16PB
John, you can look in Help for quite detailed explanations of each event and what they do. In this case there is nothing I could find to explain why moving from another form doesn't trigger the form's GotFocus event, but I suspect that this is only triggered when the form, and not any of its controls, gets the focus. Essentially when the form is clicked on itself and not any of its controls. So, if the form itself had the focus before another was opened then when the new one is closed the focus revert to the form. If a Command Button had the focus however, the form's GotFocus event wouldn't fire.

Does that make sense?
Aug 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
4
by: Bradley | last post by:
I have an A2000 database in which I have a continuous form with a tick box. There is also a text box with a conditional format that is based on the expression , if it's true then change the...
2
by: Megan | last post by:
Can you write conditional VBA code that affects only one or two records on a continuous subform? I have a form with a subform on it. The parent/ child field that links the forms is CaseID. The...
2
by: Von Bailey | last post by:
I have a form where the conditional formatting is set on some fields to bold if certain conditions are met. However, when the conditions are met some of the data that is to bold is either not...
5
by: Andrew Chanter | last post by:
Does anyone know a way you can use conditional formatting to create a banded style view as is commonly seen on the internet. (In othe words the first record appears on a gray background, the 2nd...
0
by: GGerard | last post by:
Hello With MSAccess 2000, I have created a program with forms and applied some Conditional Formatting on some of the text box.
8
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works...
4
by: midlothian | last post by:
Hello, I have conditional formatting set up on a subform based on a calculated value in the underlying query. For instance, if Sales are >$1000, the query displays "Yes," otherwise it displays...
2
by: Filips Benoit | last post by:
Dear All, Access 2003 adp on SQL_server 2005 A continious form showing 1 month based on table 'CALENDAR_MONTH_GRID' and fill with a SP. Fields: Companyname, Day1, day2, etc. The value in the...
2
by: mattloflin | last post by:
First off I have searched on this forum and others for about 1.5 hours and can't find relevant information. I have a form that is in viewsheet or datasheet mode so when you click it it looks like...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.