Solved

Lock a date field if another date field contains a value

Posted on 2011-03-24
14
277 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
  • 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 - Access MVP) earned 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

947 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now