Enable/Disable Button on Null field

lscheer

Registered User.
Local time
Today, 01:16
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
 
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)
 
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.
 
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?
 
In the OnCurrent event of the form that holds both controls.
 
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.
 
It is working for me now. See attached. I set the AppID text box to visible to see what was in it
 

Attachments

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?
 
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:
Forgot to add that I changed the query name back to qryInquiryTracking
 
Private Sub Form_Current()
Command4419.Enabled = Not IsNull(Me.ApplID)
End Sub
 
hai,

what if i want to disable button if many field
example
field 1 field 2 field 3 no data
command button disable
 
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.
 
[commandButton].Enabled = Not IsNull([field1] + [field2] + [field3])
 
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

Back
Top Bottom