Can i condition 1 record of continuous form subfile

dcavaiani

Registered User.
Local time
Today, 01:13
Joined
May 26, 2014
Messages
385
access 2002:can i condition a field to 'locked' on just one record of a continuous form subfile, based on the contents of a 2nd field in same record?
 
You can use Conditional Formatting and manipulate the Enabled property, or use code in the current event to test the 2nd field and set the locked property of the 1st field as appropriate.
 
Private Sub Customer_GotFocus()
If Me.InvoicedDate < #1/17/2015# Then
Me!Customer.Locked = True
Else
Me!Customer.Locked = False
End If
End Sub

This appears to do nothing ?
 
This is a continuous form subfile - does that make this invalid? If so, is there a way to reference to the individual records of the record in the subfile?
 
If you mean subform, no. The code will use whatever record is current.
 
I mentioned the current event of the form, which is where I would do it. Also, use dot rather than bang:

Me.Customer
 
One last thing, how do I change this IF to IS NOT NULL

If Me.InvoicedDate = #6/1/2015# Then
Me.Customer.Locked = True
Me.Customer.Enabled = False
Me.Partdesc.Locked = True
Me.Partdesc.Enabled = False
Me.Quantity.Locked = True
Me.Quantity.Enabled = False
Me.UnitPrice.Locked = True
Me.UnitPrice.Enabled = False
Else
Me.Customer.Locked = False
Me.Customer.Enabled = True
Me.Partdesc.Locked = False
Me.Partdesc.Enabled = True
Me.Quantity.Locked = False
Me.Quantity.Enabled = True
Me.UnitPrice.Locked = False
Me.UnitPrice.Enabled = True
End If
 
If Not IsNull(Me.InvoicedDate) Then

By the way, somebody is sure to come in and mention that you can cut that in half and eliminate the If/Then with

Me.Customer.Locked = Me.InvoicedDate = #6/1/2015#

I think it can be confusing to other developers, so typically don't use it.
 
I wonder who Paul is referring to there ;) but yes I agree it can be confusing to some. You forgot to put the parens:
Code:
Me.Customer.Locked = [COLOR="blue"]([/COLOR]Me.InvoicedDate = #6/1/2015#[COLOR="blue"])[/COLOR]
But this is how I would do it if I'm using that approach:
Code:
    Dim blIsTrue As Boolean
    
    blTrue = (Me.InvoicedDate = #6/1/2015#)
    
    Me.Customer.Locked = blTrue
    Me.Customer.Enabled = Not blTrue
Anyway, back to the original question, I would use IsDate() instead, cuts out all the other validation check:
Code:
    If IsDate(Me.InvoicedDate) = True Then
        If Me.InvoicedDate = #6/1/2015# Then
            Me.Customer.Locked = True
            Me.Customer.Enabled = False
            Me.Partdesc.Locked = True
            Me.Partdesc.Enabled = False
            Me.Quantity.Locked = True
            Me.Quantity.Enabled = False
            Me.UnitPrice.Locked = True
            Me.UnitPrice.Enabled = False
        Else
            Me.Customer.Locked = False
            Me.Customer.Enabled = True
            Me.Partdesc.Locked = False
            Me.Partdesc.Enabled = True
            Me.Quantity.Locked = False
            Me.Quantity.Enabled = True
            Me.UnitPrice.Locked = False
            Me.UnitPrice.Enabled = True
        End If
    End If

... a bit late with my reply...
 
Confused how the continuous form logic works when I just place a Label (LineLocked) "This Line Locked - Already Invoiced" on the detail record to indicate that "it is already Invoiced" thus you cannot update the record, yet that message appears on EACH of the continuous records NOT just on the Invoiced/Closed records?? I added these lines of code to the On Current event:

Me.LineLocked.Visible = True
...
Me.LineLocked.Visible = False
 
Visibility you'll need to do with a textbox and Conditional Formatting. You can do it with code in a report, not a form.
 
If Me.NewRecord Then
Me.LabelNewDtl.Visible = True
Else
Me.LabelNewDtl.Visible = False
End If

I was able to get the above label to work when moving to a new blank record, but I had to put it in the form footer - which is ok for that purpose.
 
Either would work on controls in the footers, not in the detail section.
 
Got it Paul. Looks like I can condition the coloring of the message/value in the textbox with Conditional Formatting, but not the presence of the value itself.
 
Not sure what you mean. You can simulate visibility by matching the fore and back colors.
 

Users who are viewing this thread

Back
Top Bottom