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, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
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 #1438459RetiredGeek
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 #1439751WSiansavell
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
-
MS-DEFCON 3: Businesses must tread carefully
by
Susan Bradley
3 hours, 58 minutes ago -
McLaren Health Care says data breach impacts 743,000 patients
by
Nibbled To Death By Ducks
4 hours, 30 minutes ago -
WhatsApp banned on House staffers’ devices
by
Alex5723
5 hours, 46 minutes ago -
Is your device eligible?
by
Susan Bradley
7 hours, 30 minutes ago -
Windows 11 Insider Preview build 26200.5661 released to DEV
by
joep517
13 hours, 41 minutes ago -
Windows 11 Insider Preview build 26120.4452 (24H2) released to BETA
by
joep517
13 hours, 42 minutes ago -
Hello Windows…My Problem is Windows Hello…
by
rdleib
14 hours, 58 minutes ago -
New Canon Printer Wants Data Sent
by
Win7and10
15 hours, 16 minutes ago -
I set up passkeys for my Microsoft account
by
Lance Whitney
4 hours, 46 minutes ago -
AI is for everyone
by
Peter Deegan
14 hours, 49 minutes ago -
Terabyte update 2025
by
Will Fastie
8 hours, 52 minutes ago -
Migrating from Windows 10 to Windows 11
by
Susan Bradley
4 hours, 25 minutes ago -
Lost sound after the upgrade to 24H2?
by
Susan Bradley
1 day, 14 hours ago -
How to move 10GB of data in C:\ProgramData\Package Cache ?
by
Alex5723
3 hours, 54 minutes ago -
Plugged in 24-7
by
CWBillow
1 day ago -
Netflix, Apple, BofA websites hijacked with fake help-desk numbers
by
Nibbled To Death By Ducks
2 days, 3 hours ago -
Have Copilot there but not taking over the screen in Word
by
CWBillow
2 days ago -
Windows 11 blocks Chrome 137.0.7151.68, 137.0.7151.69
by
Alex5723
3 days, 18 hours ago -
Are Macs immune?
by
Susan Bradley
9 hours, 51 minutes ago -
HP Envy and the Function keys
by
CWBillow
3 days, 2 hours ago -
Microsoft : Removal of unwanted drivers from Windows Update
by
Alex5723
19 hours, 20 minutes ago -
MacOS 26 beta 1 dropped support for Firewire 400/800
by
Alex5723
4 days, 5 hours ago -
Unable to update to version 22h2
by
04om
1 day, 14 hours ago -
Windows 11 Insider Preview Build 26100.4482 (24H2) released to Release Preview
by
joep517
4 days, 13 hours ago -
Windows 11 Insider Preview build 27881 released to Canary
by
joep517
4 days, 13 hours ago -
Very Quarrelsome Taskbar!
by
CWBillow
3 days, 23 hours ago -
Move OneNote Notebook OFF OneDrive and make it local
by
CWBillow
5 days, 2 hours ago -
Microsoft 365 to block file access via legacy auth protocols by default
by
Alex5723
4 days, 15 hours ago -
Is your battery draining?
by
Susan Bradley
20 hours, 59 minutes ago -
The 16-billion-record data breach that no one’s ever heard of
by
Alex5723
1 day, 14 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.