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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programatically Switching form elements on / off

Status
Not open for further replies.

Kalisto

Programmer
Feb 18, 2003
997
GB
The application in question has a number of forms.
One of these forms has a subform that lists a series of recommendations as the results of a query.

Now, in the case that the id of the recommendation is 10 or 13, then a set of text boxes are required, so that data can be recorded against this item in the table.

I have created the textboxes on the sub form, and set visibility to false.

I have a simple piece of code (below) to switch the visibility on, but it wont work. I suspect it is because I have the code placed in the wrong event.

So, What is the right event to use, so that when the data is queried from the database, if a record is pulled back with an ID of 13 then the text boxes visible property is set to true?

Code:
Private Sub Form_Query()
If (tbRecId.Text = "10") Or (tbRecId.Text = "13") Then

    tbWarrantyCost1.Visible = True
    tbWarrantyCost2.Visible = True
    tbWarrantyCost3.Visible = True
    tbWarrantyMonth1.Visible = True
    tbWarrantyMonth2.Visible = True
    tbWarrantyMonth3.Visible = True
End If
End Sub

And as a sub question / design question, currently I have the recId being pulled into a textbox. Is this the best way (being as its the key) or can I just refer to it in the datasource without sticking it into a control?
K
 
I'd use the Current event procedure.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Cheers. If I change the SubForm to have the OnCurrent Event (and move the code aboce to that event) then the form doesnt render. :-/
 
What is tbRecId ?
If a textbox then its Text property is available only when it has the focus.
Test its Value property instead.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks, thats working better. However, it has revealed another issue (one that probably shows up mu limited experience in Access)

If there are say 5 results in the sub query, and one of them has the appropiate id, then when that record is Current, it draws the text boxes for all 5 of the records.

Is there any way of telling the sub form to only draw the text boxes for those records that match a record with the appropriate ID?

K
 
. . . and if you drop the [blue]Text[/blue] property?

Calvin.gif
See Ya! . . . . . .

Be sure to see FAQ219-2884:
 
An alternate way is to play with conditional formatting.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Cheers, but the reason Ive ended up playing with this in the code is that conditional formatting lets me play with the font style, colour, end enabled. But it doesnt let me set the visibility.

K
 
Enabled = False doesn't suffice ?
To emulate the visibility you may set the foreground color to the same as the background color.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Unfortunately, for this customer enabled won't suffice.
I'll try the visibility thing, however, it will leave white space at the bottom of those bits of the sub-report - again something that the customer has issues with. (Can you say "Moon on a Stick?")

Its all helped so far, so I'll play about with it, then come back and sort out a star or 2..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top