Full Version: Hide Control on Form Given Condition
UtterAccess Forums > Microsoft® Access > Access Forms
lhcpr
Hi all,
quick question.
Oneed help hiding a control (check box) on a data entry form. What I need to do is have the check box control hidden whilst a nearby text box remains empty. When text is entered into the text box, I need the check box control to be displayed.
Any suggestions would be great. Please keep in mind that my experince is limited.
Cheers,
lhcpr
freakazeud
Hi,
try this on the on current event of the form:
If Len(Me.YourControl & vbNullString) = 0 Then
Me.YourCheckbox.Visible = False
Else
Me.YourCheckbox.Visible = True
End If
ScottGem
If IsNull(me.txtcontrol) Then
Me.chkControl.Visible = True
Else
Me.chkcontrol.Visible = False
End If
That would go in After Update event of the text box. I would also put it in the On Current event of the form if you use the form for viewing/editing previous records.
kbrewster
In the form's OnCurrent event place the following code...

CODE
If IsNull(Me.textbox) or Me.textbox <>"" Then
e.checkbox.Visible = True
Else
Me.checkbox.visible = False
End If


You will have to change "textbox" to the name of your textbox, and change "checkbox" to the name of the checkbox.

WHOOPS...mine was backwards...

CODE
If IsNull(Me.textbox) or Me.textbox = ""Then
Me.checkbox.Visible = false
Else
Me.checkbox.visible = true
End If

Edited by: kbrewster on Tue Jan 17 15:37:40 EST 2006.
R. Hicks
Use the following example in the On Current event of the form:

CODE
Private Sub Form_Current()
e.YourChkbox.Visible = Len(Me.YourTxtbox & vbNullString) <> 0
End Sub

Also ... execute the same line in the After Update event of the txtbox to show the chbox when a value is entered.

CODE
Private Sub YourTxtbox_AfterUpdate()
Me.YourChkbox.Visible = Len(Me.YourTxtbox & vbNullString) <> 0
End Sub


Note .. change "YourChkbox and YourTxtbox" to the correct name of your controls ...

RDH
R. Hicks
LOL .. all replies uses an If/Else/End If to do the task ... this is not needed ...
DH
kbrewster
I am learning all kinds of new things from you today Ricky!! grin.gif
R. Hicks
LOL .. this is easily overlooked in this situation.
Basically .. you can "toggle" a boolean value with another boolean value (as I did in my solution) ...
DH
lhcpr
Wow, talk about a number ways to skin a cat. Will play around with it a bit and get back to you.
Thanks all,
lhcpr
R. Hicks
What I posted should do exactly what you need without the use of an If/Else/End If statement ....
DH
lhcpr
Riddle me this,
Can I do this for multiple text/check controls. I have around 30 I need to do in this manner???
lhcpr
R. Hicks
30 ???
This throws up a flag that you may have a struture problem in your application ...
What do all these txtboxes and checkboxes represent in your application ???
DH
lhcpr
Ok, a bit of background might make this easier.
I have a form which has 30 text boxes for data entry. If text is entered into any of these boxs, a check box verifying the value would appear. If the text box was left empty, there is no need for the verification (and hence for the check box; it could remain hidden). In the end, if a value is entered, I need to determine if it has been verified or not.
I hope that this helps a bit. Any ideas??? Thanks for all the help. It is appreciated,
lhcpr
R. Hicks
That has not answered the question .. of what do these textboxes and checkboxes represent ...
What values are entered in the txtboxes ???
And what exactly do the associalted checkboxes do ???
Are the checkboxes bound to fields in the table ???
Can you post the table stucture where these values are being stored ???

RDH
lhcpr
Righteo then,
I have attached an example to help with the situation. Hope that it gives a little more insight. It is pretty cut down . I am still planning it. The form has been put together just using a query of tables PCI and Complete.
So again, what I wish to do is have a check box displayed if a nearby text box is populated. This will be the case for around 30 examples. Not every text box will have text entered. The check box is to verify the data that has been entered in the text box. I could just grey out the check boxes for those text boxes which have not been populated.
Thanks for all the help, this is a great forum. Again, I am fairly newish, slow please!!!
Cheers,
lhcpr
lhcpr
To answer your questions,
) Any numeric or alphanumeric data can be entered
2) Check boxes verify if the data entered is complete or not complete
3) The check boxes are bound to fields in a separate 'Complete?' table
Thanx
lhcpr
R. Hicks
Your structure is not properly normalized as I feared ...
Oassume these are test procedures ...
Each procedure should be a seperate record in a table and not as multiple fields in a record ...
This is known as "repeating groups" and will cause you more problems than you can imagine later in the developement of the application ...
DH
lhcpr
Thanks for taking the time to look at my example.
If I have understood this correctly, I should have a separate table for each procedure. For each record I could then enter the details. Each record would have a complete/incomplete checkbox for each procedure.
If I do this, can I then query by incomplete/complete to determine which procedures were complete or not??
Again, thanks for all the help. It has been invaluable. Maybe one day if I get good enough I can contribute grin.gif A lot of learning........
lhcpr
R. Hicks
No ...
Each procedure performed should be a seperate record in one table.
DH
ScottGem
yeah I keep forgetting about setting a boolean using a boolean value. Old habits die hard.

I also agree with Ricky recommendations for normalizing your database. This would actually make it EASIER to query for incomplete tests. You just need to query one field in one table.
Edited by: ScottGem on Tue Jan 17 18:00:53 EST 2006.
lhcpr
Ok, I understand that. Each procedure is a field in a record. I can see how this would simplify the query, although I am having some difficulty seeing how I can integrate it into my DB.
I have a simple table relationship structure. I have a patient and surgeon info page (CCF1); a unique ID is automatically created here. For each ID I need to get information for the 30 odd procedures and check if they were complete. There are MANY ID's!!! If I have each procedure as a field in the record, how do I relate this back to the ID #. That is, for each ID, I need to be related and have information on the 30 procedures.
I am not sure if I have explained this well enough. My example is in my previous posts. Any ideas on how best to go about this???
Thanks once again,
lhcpr
ScottGem
your table should be look like:
blPatientProcedures
PatientProcedureID (PK autonumber)
PatientID (FK)
ProcedureID (FK)
Results
Complete
You enter procedures using a subform with the patient record on the main form. The patientID would be automatically entered. You would only add records for procedures that will be performed.
lhcpr
Scott,
think this table will work. Just to clarify a couple of things:
1) I need to create another table called 'Procedures'. This will have Procedure ID as the primary key.
2) The primary key of the 'Procedures' table (Procedure ID) will be the foreign key of the 'Patient Procedures' table (the one you posted above).
I hope that I have understood this right. There was definitely some bad DB structure happening on my part. Thanks for the heads up one and all.
Cheers,
lhcpr
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.