Disable a date field if another is null (1 Viewer)

Big Pat

Registered User.
Local time
Today, 10:47
Joined
Sep 29, 2004
Messages
555
Hi,

I have two date fields on my form, for when a particular process is suspended and then unsuspended. Some processes will never be suspended, so in these cases I want to disable accidental input to the Unsuspended field.

I thought I could do it like this

Code:
If Me.Study_wide_suspension.Value Is Null Then
    Me.Study_wide_Unsuspension.Enabled = False
Else
    Me.Study_wide_Unsuspension.Enabled = True
End If

but that gives me Run-time Error 424 Object required. This code is on the OnCurrent event by the way. I plan to have similar code on the AfterUpdate event of the Suspension field.

If I use = Null rather than Is Null then I don't get an error message, but it doesn't actually work, i.e. the Unsuspension field is enabled even if the Suspension field hasn't been completed.

I read something somewhere about a date never really being null, so I tried =0 Again, no error, but the disabling doesn't work.

Where am I going wrong here? In case it's relevant, the fields are on a form called "frm01Study" on TabCtl41 (which I never renamed) on a page called pgGlobal which is the second of three tabs.

Thanks,

Pat.
 

pr2-eugin

Super Moderator
Local time
Today, 10:47
Joined
Nov 30, 2011
Messages
8,494
Is Null and IsNull() are different.. Is Null is used in SQL for Queries, whereas IsNull() is a VBA Function.. So try..
Code:
If IsNull(Me.Study_wide_suspension) Then
    Me.Study_wide_Unsuspension.Enabled = False
Else
    Me.Study_wide_Unsuspension.Enabled = True
End If
Null is not a value, so it cannot be compared with, by using Equals.. There are several ways you can tacke Null values.. Using Nz(), Len(theVariable & vbNullString) = 0.. I prefer the Len() method as it will not only catch Null but also Zero Length Strings..
Code:
If Len(Me.Study_wide_suspension & vbNullString) = 0 Then
    Me.Study_wide_Unsuspension.Enabled = False
Else
    Me.Study_wide_Unsuspension.Enabled = True
End If
 

Big Pat

Registered User.
Local time
Today, 10:47
Joined
Sep 29, 2004
Messages
555
You, sir, are a diamond!

The first one worked perfectly. As for the second, I'll admit I've never quite got the distinction between NULL and zero-length string (I assume you mean "") and I know this is something i ought to get to grips with. Manana! :)

Thank you.
 

gemma-the-husky

Super Moderator
Staff member
Local time
Today, 10:47
Joined
Sep 12, 2006
Messages
15,638
you need to put this code in the forms current event

you also need ot add it to the dependent control's afterupdate event to unlock the field after data is entered.

which then begs the question ...

what if someone enters data in controlA - thereby unlocking the date.
then enters a date
then goes back and deletes the data in controlA?
 

Rx_

Nothing In Moderation
Local time
Today, 03:47
Joined
Oct 22, 2009
Messages
2,803
That is a very good point! This is one of the challanges I face. The Rule based form concept.

Good documentation about this very subject seems to be rare. Any good demo's or papers to suggest would be welcome.
 

Big Pat

Registered User.
Local time
Today, 10:47
Joined
Sep 29, 2004
Messages
555
Thanks Dave -

I did mention in the first post that I plan to have similar code on the AfterUpdate event...but I needed help to get the code right first! ...so I will get round to that.

As for someone taking out a date they have previously entered, that also occurred to me. I haven't coded this yet - and I need to clear it with the manager of the staff who'll be using this - but I thought I would include a line such as... Unsuspended.value = null ...in the AfterUpdate event of the 'Suspended' control, basically overriding the unsuspension.
 

Users who are viewing this thread

Top Bottom