Solved

Lock a date field if another date field contains a value

Posted on 2011-03-24
14
280 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

730 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