Lock a date field if another date field contains a value

I want to lock a date field if another date field on the form has a value entered in it.  How can I do this?

--Steve
SteveL13Asked:
Who is Participating?
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Connect With a Mentor Database ArchitectCommented:
Lets try this:  Be sure the AU event is triggering when you delete the date value ...

Private Sub txtReschDropDueDate_AfterUpdate()

   IF  Nz(Me.txtReschDropDueDate , "") >""  Then
           Me.Text158.Locked = True
   Else
           Me.Text158.Locked = False          
   End If

End Sub
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
You can start with this:

Private Sub Form_Current()

Me.TheDateFieldYouWantToLock.Locked =  Not IsNull(Me.YourDateFieldWithValue)

End Sub

mx
0
 
SteveL13Author Commented:
So for using real field names I have...

    Me.Text158.Locked = Not IsNull(Me.txtReschDropDueDate)
    Me.Text158.Locked = IsNull(Me.txtReschDropDueDate)

The 2nd line of code doesn't work if the field with value is empty.  How should it read?

--Steve
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Does the first line work?  That's the condition you specified:

"I want to lock a date field if another date field on the form has a value entered in it."

?

mx
0
 
MINDSUPERBCommented:
You may use the IF-Then Statement as presented below:

If Not IsNull(Me.txtReschDropDueDate) Then
Me.Text158.Locked = True
Else
Me.Text158.Locked = False
End If


Sincerely,
Ed
0
 
SteveL13Author Commented:
Close,  but it doesn't unlock unless I exit the form and re-open it.
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Well ... my first post was just for started.  Now we need to add code as follows:

Private Sub txtReschDropDueDate_AfterUpdate()

Me.Text158.Locked = Not IsNull(Me.txtReschDropDueDate)

End Sub

So ... once a date is entered into txtReschDropDueDate ... Text158 will get handled

mx
0
 
SteveL13Author Commented:
This doesn't unlock the text158 field after removing value from txtReschDropDueDate either unless I close and relaunch the form.  
0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
Did you confirm the AfterUpdate event is triggering ?

Try this mod:


Private Sub txtReschDropDueDate_AfterUpdate()

Me.Text158.Locked = Not ( Nz(Me.txtReschDropDueDate , "") = "")

End Sub
0
 
SteveL13Author Commented:
This still does not work.  If a date is entered in txtReschDropDueDate then text158 DOES lock.  This is great.  But if I clear the date in txtReschDropDueDate the text158 does not unlock which is what I want to have happen.

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ok ... how exactly are you 'clearing' the date ?

mx
0
 
SteveL13Author Commented:
Just deleting the date in the field.
0
 
SteveL13Author Commented:
Still...

This still does not work.  If a date is entered in txtReschDropDueDate then text158 DOES lock.  This is great.  But if I clear the date in txtReschDropDueDate the text158 does not unlock which is what I want to have happen.

0
 
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database ArchitectCommented:
ook ...can you upload a db that does this ... an point to what I need to make this happen ?

mx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.