Enable/Disable Button on Null field (1 Viewer)

lscheer

Registered User.
Local time
Today, 01:20
Joined
Jan 20, 2000
Messages
185
I have a command button on a form that I only want to enable when the value of one of the text fields is not null (has data) and want the button to be disabled when the text field has no data. For some reason, the code does not seem to be working; any suggestions?

If IsNull(Me!ApplID) Then
Me.Command4419.Enabled = False
Else
Me.Command4419.Enabled = True
End If
 

boblarson

Smeghead
Local time
Yesterday, 17:20
Joined
Jan 12, 2001
Messages
32,059
It could be that the field has a zero-length string and is not null, but LOOKS Null.

I handle it like this (with one line of code):

Code:
Me.Command4419.Enabled = (Len(Me.AppID & "") <> 0)
 

lscheer

Registered User.
Local time
Today, 01:20
Joined
Jan 20, 2000
Messages
185
This doesn't seem to work either; I did double-check the field and all of the "blank" fields are in fact Null and not zero-length strings.
 

boblarson

Smeghead
Local time
Yesterday, 17:20
Joined
Jan 12, 2001
Messages
32,059
This doesn't seem to work either; I did double-check the field and all of the "blank" fields are in fact Null and not zero-length strings.

Where do you have the code?
 

lscheer

Registered User.
Local time
Today, 01:20
Joined
Jan 20, 2000
Messages
185
In the OnCurrent event of the form that holds both controls.
 

boblarson

Smeghead
Local time
Yesterday, 17:20
Joined
Jan 12, 2001
Messages
32,059
1. Make sure the names are all correct.

2. If that fails, perhaps you can upload the form and any tables (minus any sensitive data) that go with that form so we can see what is happening.
 

lscheer

Registered User.
Local time
Today, 01:20
Joined
Jan 20, 2000
Messages
185
Here is the db
 

Attachments

  • NeedsDB.zip
    79.3 KB · Views: 361

boblarson

Smeghead
Local time
Yesterday, 17:20
Joined
Jan 12, 2001
Messages
32,059
It is working for me now. See attached. I set the AppID text box to visible to see what was in it
 

Attachments

  • NeedsMockUp_RevBL.zip
    81.2 KB · Views: 607

dbDamo

Registered User.
Local time
Today, 01:20
Joined
May 15, 2009
Messages
395
Worked fine for me too. What did you change Bob? All I did was remove the ' and it was fine. I am assuming the OP added the ' before uploading the Database and wasn't trying to run the code like this?
 

lscheer

Registered User.
Local time
Today, 01:20
Joined
Jan 20, 2000
Messages
185
I realized after looking at Bob's solution that I had inadvertently fixed the problem myself. Somehow the code wasn't working (either Bob's or my original) because of the underlying recordsource. The RS for the form had been based on a nested query unnecessarily. When I adjusted it to simplify it for posting, I changed the RS to be based on a table and query instead of two queries, and that fixed it. My original code now works as well as Bob's.

PS - I'm assuming that the code wasn't working because the faulty recordsource was not updateable...?
 
Last edited:

dbDamo

Registered User.
Local time
Today, 01:20
Joined
May 15, 2009
Messages
395
Forgot to add that I changed the query name back to qryInquiryTracking
 

pmeyssonnier

New member
Local time
Today, 02:20
Joined
Apr 19, 2020
Messages
1
Private Sub Form_Current()
Command4419.Enabled = Not IsNull(Me.ApplID)
End Sub
 

Akai

New member
Local time
Today, 08:20
Joined
Jan 12, 2022
Messages
1
hai,

what if i want to disable button if many field
example
field 1 field 2 field 3 no data
command button disable
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:20
Joined
Sep 21, 2011
Messages
14,607
Best to start your own thread?

Anyway, walk through the controls and if they have a value of your choice in the Tag property, then disable the button.
Disable on the first empty control found and exit the loop.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:20
Joined
May 7, 2009
Messages
19,249
[commandButton].Enabled = Not IsNull([field1] + [field2] + [field3])
 

Cotswold

Active member
Local time
Today, 01:20
Joined
Dec 31, 2020
Messages
532
I don't allow Nulls in my tables, which can be particularly annoying in calcs. When a new record is added,
if important a Zero or Space(1) is inserted as applicable. If a user creates a null entry, Text or Number,
the OnChange() will correct it with one of my standard Functions. Nulls are a damn nuisance.
 

Users who are viewing this thread

Top Bottom