TOPIC: Visible/Non-Visible controls in Access
#959
Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Here is my code:

Code:


Controller
{
Controls:
(Access
title: "Enter Lot Data"
lots
(Vert
(Form
(lotNumber group:0) (planName group:1)  (streetAddress group:2) (streetName group:3) nl
(purchasePrice group:0) (upgradesCost group:1) (totalCost group: 2) nl
(lastName1 group:0) (firstName1 group:1) (lastName2 group:2) (firstName2 group:3) nl nl nl
(homePhone group:0) nl
(cellPhone1 group:0) (cellPhone2 group:2) nl
(email1 group:0) (email2 group:2) nl nl nl
(forSale? group:0) (askingPrice group:1) (rented? group:2) nl nl
(mailAddress group:0)
)
(Skip)
(Browse
"sales",
columns: (saleDate, saleAmount, saleSource, saleNote)
linkField: lotNumber,
name: "lotNumberMain"
)
)
)
}



What I want to do is Show/Hide the askingPrice field based on whether or not the forSale? checkbox is clicked.

Believe or not, I do search all over this site before asking my questions :)
 
 
#960
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Asking questions is a good thing. A lot of this stuff is not easy to figure out at first.

Hiding a control can be done with the SetVisible method which is implemented in Hwnd and inherited by most controls.

There are a few messages you could use to call SetVisible. Access_AfterField is probably the best for this:

Code:

Access_AfterField(field, value)
    {
    if field is 'forSale?'
        .askingPrice.SetVisible(value is true)
    }



This is assuming our convention of creating a member referencing controls you need to access in New:

Code:

New()
    {
    .askingPrice = .FindControl('askingPrice')
    }



You could do the FindControl in Access_AfterField, but it can be a little slow if you have a lot of controls so we prefer to just find it once, in New.

My usual warning - I haven't actually run this code so there may be mistakes.
 
 
andrew
 
#961
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
It works as expected, thanks. But I didn't look far enough ahead. I should have said I also would like it to be visible or not depending on the value of forSale? as we move through the records. The controls visibility stays at whatever it was the last time we clicked.
 
 
#962
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
I forgot about that too. You can use Access_BeforeRecord

Code:

Access_BeforeRecord(x)
    {
    .askingPrice.SetVisible(x.forSale? is true)
    }

 
 
andrew
 
#964
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
That gives an error of:

uninitialized member #Data_Access_askingPrice
 
 
#966
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Access_BeforeRecord is probably getting called before the New has run. Try:

Code:

askingPrice: false
Access_BeforeRecord(x)
    {
    if .askingPrice isnt false
        .askingPrice.SetVisible(x.forSale? is true)
    }

 
 
andrew
 
#968
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Got it!

Some folks might wonder why I worry about such a small detail, but it gives the project a more professional look. And making it work helps me learn the system.

Thanks again.
 
 
#969
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Now that you have it working, I'll mention that it isn't always a good idea to hide things. The problem is that users get frustrated trying to find something that's been hidden. They might only have to click on a checkbox but they often don't figure that out. Sometimes it's better to just disable the control rather than hide it. Especially if you lay out the controls so the disabled control is next to the checkbox so they have a clue. For this you could use the same approach (with SetEnabled instead of SetVisible) or somewhat easier, just define Rule_askingPrice__protect (a separate library record):

Code:

function ()
    {
    return .forSale? isnt true
    }



It seems backwards because it has to return true if the control should be protected (disabled).
 
 
andrew
 
#970
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Good advice and I appreciate your showing me how to do it.

I wonder, though, whether or not a user might try to click into the disabled control and get confused when nothing happens. When it's done I'll spring it on a few of my friends and see how they handle it.
 
 
#971
Re:Visible/Non-Visible controls in Access 3 Years, 1 Month ago
Good point, although our users (even new ones) seem to understand a "grayed out" control is not usable.
 
 
andrew