Solved

Lock a date field if another date field contains a value

Posted on 2011-03-24
14
278 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
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 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 - 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

786 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