Changing property settings by code

RexesOperator

Registered User.
Local time
Today, 00:03
Joined
Jul 15, 2006
Messages
604
This is getting into some stratospheric territory for me.

I am trying to change the visibility property of a label and corresponding text box, based on the contents of a different combo box. cboHow is a combo box that uses a value list as its row source, since the content of the list won't change. There are three fields that I need when the content of cboHow = "FIS". Otherwise I don't need them and I don't want to see them. My code is below:

Private Sub txtFISDepartmentNumber_BeforeUpdate(Cancel As Integer)
If cboHow <> "FIS" Then
lblFISDepartmentNumber.Visible = False
txtFISDepartmentNumber.Visible = False
Else: lblFISDepartmentNumber.Visible = True
txtFISDepartmentNumber.Visible = True
End Sub

At the moment there is no error code, but the label and text field don't respond by becoming visible/invisible when the contents of cboHow changes. Do I put this code with the txtFISDepartmentNumber or in cboHow? and do I use BeforeUpdate or AfterUpdate? Should I have a separate If..Then..Else for the label and the text box?

I have been playing around with this for several hours now and seem to be going in circles.

I am using A2K
 
a few things

1. you don't really need this code in the before update event of the departnumber.

2. you dont need to touch the label - if the label is attached to the textbox, they will be both be visible/not visible as a pair

3. you really need this attached to the cbohow afterupdate event, and you can do it more elegantly with this one line. since visible is a boolean flag, you can do this by equating the visible property with a boolean evaluation as follows. Hope it makes sense

Code:
sub cbohow_afterupdate event
txtFISDepartmentNumber.Visible = (cbohow="FIS")

you also need to test the setting when you change to a different records, so you need this same statement attached to the oncurrent event
 
Either I'm up late (I'm near Toronto, Canada) or you're up awfully early (I see you're in the UK). I'm glad for both, because this solution works like a charm.

I didn't know that labels were attached to a text box - makes too much sense for microsoft! Is it safe to assume that is NOT the case with unbound text boxes?
 
No.

Unbound text boxes work the same as gemma-the-husky explained.
 
i am in the UK and couldn't sleep, so I had a look at some postings, and changed a bit of code I had been working on

When you add a text box (or indeed any control) to a form the label that comes with it is attached to the control and doesn't need any further attention - it takes the control's display properties, effectively.

Unattached labels would need to be addressed individually.
 
Now that I have this working (many thanks) for future data entry, can I make the items invisible on earlier transactions when cboHow <> FIS?

I tried Private Sub cboHow_BeforeUpdate(), but that generates an error. Logically it should (BeforeUpdate, OnCurrent and AfterUpdate shouldn't be the same), but how do I attach the code so these field are invisible when they haven't been used.
 
that's why you need things like this in the current event - so they work on existing data, as well as new data.

good luck
 

Users who are viewing this thread

Back
Top Bottom