Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Make buttons visible on subform based on function 1

Status
Not open for further replies.

lollyjar

Programmer
Aug 3, 2003
29
GB
I have a Form with a Subform (continuous). The Subform displays rows of information, the number of which varies depending on values on the subform. Each row also has a button which is used to bring up another form with more detail for that row.

The trouble is that for some rows, no details are available, and I have a message box that informs the users of this after they click the button. I would prefer to disable (or make invisible) the button on the row based on the information in each row.

What event do I need to use to call my function to decide whether details are available and to hide or display the buttons?

Cheers,
 
lollyjar

Working with subforms is a bit tricky. Setting attributes for unbound control objects may set the attribute for the control for each line.

Each row also has a button which is used to bring up another form with more detail for that row.

I used this approach too -- I find it works well.

The trouble is that for some rows, no details are available, and I have a message box
Not sure about this. You mean you have part of a record and not the other part?

You may try OnCurrent event procedure

Assumption
- DLookUp will determine if component is present or not
- YourField - name of field you are looking for
- Primary key - assume primary key is avaiable on the subform and available for the lookup - your probably use it to open up your form.

Code:
Me.Yourbutton.Visible =(DLookup("[YourField]", "YourDetailTable", "[PrimaryKey] = " & Me.PrimaryKey))
(I have to thank the Cajun for this approach, instead of If / Else

Another approach would be to use DoubleClick event (with perhaps conditional formatting)

Richard



 
Thanks for the response, I will clarify the second quote above. Some rows in the subform have extra information stored elsewhere. The buttons are used to open a form to view this extra information. Many of the rows, however, do not have any additional information and therefore the details button needs to be hidden.

If I use the OnCurrent event, the button visibility is set for every row, rather than just the row that it refers to.

Does this clarify it at all?
 
lollyjar

Hmmmm.
You could use NZ(DLookUp(...),0) assigned to an unbound field
If found, the the filed stores the ID number, if not, then the number stored is 0. Then use conditional formatting to change the colour of the field if =0 or >0. The end user could then use the double click event.

You could even make the text colour the same as the field colour, and size the field to look like a small square light - green light / red light thing. (If the text and field colour is the same, the end user can not see the text - but you know this already)

Richard
 
How are ya lollyjar . . . . .

What you want requires [blue]Conditional Formatting[/blue] and wont work for a Command Button. However it does work for a textbox. You can disable the textbox, but ya can't hide it.

1) Add an unbound textbox(instead of the button) with Special Effect set to raised (looks like a button) and set your code in the [blue]On Click Event[/blue]. Then set your [blue]Conditional Formatting[/blue] attributes.

An alternate solution would be to use the [blue]Double Click Event[/blue] of any control in a record.

Calvin.gif
See Ya! . . . . . .
 
Hi Guys,

Thanks for the tips, it looks like it will work but...

I've never used conditional formatting on a text box on a form. How do I do this (if it is available in Access97)?

Cheers
 
lollyjar . . . .

So sorry. You need 2k or above. . . .

As another alternative, with a single button in the forms header or footer, you can use the screen objects [blue]Previous Control Property[/blue] to go back to the selected record and pick up your data from there.

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top