?
Solved

Lock a date field if another date field contains a value

Posted on 2011-03-24
14
Medium Priority
?
283 Views
Last Modified: 2013-11-05
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
0
Comment
Question by:SteveL13
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
14 Comments
 
LVL 75
ID: 35208943
You can start with this:

Private Sub Form_Current()

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

End Sub

mx
0
 

Author Comment

by:SteveL13
ID: 35209045
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
 
LVL 75
ID: 35209152
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 35209163
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
 

Author Comment

by:SteveL13
ID: 35209219
Close,  but it doesn't unlock unless I exit the form and re-open it.
0
 
LVL 75
ID: 35209263
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
 

Author Comment

by:SteveL13
ID: 35209541
This doesn't unlock the text158 field after removing value from txtReschDropDueDate either unless I close and relaunch the form.  
0
 
LVL 75
ID: 35209600
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
 

Author Comment

by:SteveL13
ID: 35209638
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
 
LVL 75
ID: 35209653
ok ... how exactly are you 'clearing' the date ?

mx
0
 

Author Comment

by:SteveL13
ID: 35209749
Just deleting the date in the field.
0
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 35209816
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
 

Author Comment

by:SteveL13
ID: 35210657
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
 
LVL 75
ID: 35210676
ook ...can you upload a db that does this ... an point to what I need to make this happen ?

mx
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question