I have two forms in a database. What I want to do is in a Name control in form 1, I want the text to be Red, if a control in form 2 contains data, but black if it is empty. I know how to refer to a control on the same form or subform, but not another form in the same database.
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Check whether control is empty
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Check whether control is empty
- This topic has 18 replies, 5 voices, and was last updated 11 years, 3 months ago.
Viewing 13 reply threadsAuthorReplies-
WBell
AskWoody_MVP -
WSrobm
AskWoody Lounger -
WBell
AskWoody_MVP -
WSrobm
AskWoody LoungerFebruary 10, 2014 at 9:49 am #1438183How do I check a field in a table? I’ve tried looking up DLookup, but can’t see anything that relates to my problem. From the form, I want to check if a field in the table has a Null value. If so, format the text in the form as black. If it contains data, format the text in the form to Red.
-
RetiredGeek
AskWoody_MVPFebruary 10, 2014 at 11:36 am #1438191Rob,
I messed around with this and came up with this code which seems to work.
Code:Option Compare Database Option Explicit Private Sub Form_Current() If Not CurrentProject.AllForms("Contracts1").IsLoaded Then MsgBox "The form Contracts1 is not currently loaded!", _ vbOKOnly + vbInformation, "Error: Missing Form" End If If IsNull(Forms!Contracts1!FormName) Then Me!ReleaseDate.BackColor = RGB(0, 0, 0) Else Me!ReleaseDate.BackColor = RGB(255, 0, 0) End If End Sub Private Sub Form_Activate() Me.Refresh End Sub
Note: The Refresh in the Form_Active routine does NOT work and it also doesn’t work if placed in a Form_GotFocus event! However, if you press F5 it works as it should, go figure! Hopefully, one of our Access Gurus will come up with a solution.
36211-red 36212-black
Of course you’ll have to adjust the Form & Field names as fit your situation. Note: the code goes in the form which gets the color change!
HTH :cheers: -
WSrobm
AskWoody Lounger -
WSrobm
AskWoody Lounger
-
-
RetiredGeek
AskWoody_MVPFebruary 11, 2014 at 8:28 am #1438339Rob,
Yes both forms have to be loaded/open the code even checks to make sure the second form is loaded. HTH :cheers:
-
RetiredGeek
AskWoody_MVPFebruary 12, 2014 at 5:21 am #1438444Rob,
Ok this code works for me.
Code:Option Compare Database Option Explicit Private Sub Form_Current() If IsNull(DLookup("DeceasedDte", "Hospital", "[PatientNo] = " & Me!PatientNo)) Then Me!ReleaseDate.BackColor = RGB(0, 0, 0) Else Me!ReleaseDate.BackColor = RGB(255, 0, 0) End If End Sub
[noparse]
The DLookup statement breaks down as follows:
DeceasedDte = The fieldname I want the value from.
Hospital = The data table where I’m searching
[PatientNo] = The fieldname I’m searching in Hospital.
Me!PatientNo = The search value from the form.Note: beware of the quote marks as they are essential!
[/noparse]
Replace the above values with those appropriate to your situation.Also don’t forget to replace the Me!ReleaseDate.BackColor statements with the field name of your form that gets the color change.
HTH :cheers:
-
WSrobm
AskWoody LoungerFebruary 12, 2014 at 6:19 am #1438447Ok, I’ve messed around with the tables, etc. and managed to get the data into the form using a query, so I have managed to get the control I need to check, in the form. I still can’t get anything to work using IsNull. I have a combo box (combo6) which selects the surname. A control on the form is called SIA. What I want is, after a Surname is selected, if control SIA contains any data, the background changes, but I can’t get it to work. I’ve got the Event in the After Update property of combo6, but I’m not sure if this is right.
-
WSrobm
AskWoody Lounger -
WSrobm
AskWoody LoungerFebruary 12, 2014 at 7:51 am #1438453Sorry if I’m a bit thick but, I don’t understand the ‘The search value from the form’ bit. This is the code I’ve got
Code:Option Compare Database Option Explicit Private Sub Form_Current() If IsNull(DLookup(“SIA”, “tblMaster Sheet”, “[FORNAME] = ” & Me!FORENAME)) Then Me!SURNAME.BackColor = RGB(0, 0, 0) Else Me!SURNAME.BackColor = RGB(255, 0, 0) End If End Sub
but it’s not working. What I want to happen is when I select the surname from the combo, it checks the SIA in the tblMaster Sheet, to see if it contains data. If it does the background of the Surname is Red, if not, black.
-
-
-
RetiredGeek
AskWoody_MVPFebruary 12, 2014 at 8:55 am #1438457Rob,
Ok, place the code in the AfterUpdate event of your combo box vs the Form_Current event! HTH :cheers:
-
WSrobm
AskWoody LoungerFebruary 12, 2014 at 9:39 am #1438459 -
RetiredGeek
AskWoody_MVPFebruary 12, 2014 at 10:04 am #1438465Rob,
That is correct! Have you move the code to the ComboBox controls AfterUpdate event?
BTW: I forgot to mention that if you are checking on a name field you could have problems if you have more than one person with the same name. As I understand it DLookup will only find the 1st matching record in the DB.
Here’s the reference notice the limitation under the Remarks section. HTH :cheers:
-
WSrobm
AskWoody LoungerFebruary 18, 2014 at 1:55 am #1439751 -
WSiansavell
AskWoody Lounger -
WSCronk
AskWoody Lounger
-
Viewing 13 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Have Copilot there but not taking over the screen in Word
by
CWBillow
3 hours, 45 minutes ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
1 day, 2 hours ago -
Are Macs immune?
by
Susan Bradley
23 hours, 30 minutes ago -
HP Envy and the Function keys
by
CWBillow
9 hours, 51 minutes ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
1 day, 13 hours ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
1 day, 13 hours ago -
Unable to update to version 22h2
by
04om
4 hours, 12 minutes ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
1 day, 21 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
1 day, 21 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
1 day, 7 hours ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
2 days, 10 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
1 day, 22 hours ago -
Is your battery draining?
by
Susan Bradley
10 hours, 10 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
3 hours, 47 minutes ago -
Weasel Words Rule Too Many Data Breach Notifications
by
Nibbled To Death By Ducks
2 days, 13 hours ago -
Windows Command Prompt and Powershell will not open as Administrator
by
Gordski
5 minutes ago -
Intel Management Engine (Intel ME) Security Issue
by
PL1
1 day, 22 hours ago -
Old Geek Forced to Update. Buy a Win 11 PC? Yikes! How do I cope?
by
RonE22
1 day, 14 hours ago -
National scam day
by
Susan Bradley
21 hours, 22 minutes ago -
macOS Tahoe 26 the end of the road for Intel Macs, OCLP, Hackintosh
by
Alex5723
1 day, 17 hours ago -
Cyberattack on some Washington Post journalists’ email accounts
by
Bob99
3 days, 15 hours ago -
Tools to support internet discussions
by
Kathy Stevens
2 days, 3 hours ago -
How get Group Policy to allow specific Driver to download?
by
Tex265
3 days, 6 hours ago -
AI is good sometimes
by
Susan Bradley
3 days, 22 hours ago -
Mozilla quietly tests Perplexity AI as a New Firefox Search Option
by
Alex5723
3 days, 12 hours ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
4 days, 22 hours ago -
June KB5060842 update broke DHCP server service
by
Alex5723
4 days, 21 hours ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
5 days, 1 hour ago -
Excessive security alerts
by
WSSebastian42
3 days, 15 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
5 days, 10 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.