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

Repost Hide or display a field on a form based upon what is in a field 1

Status
Not open for further replies.

TommyTea

Programmer
Nov 7, 2002
43
US
I have a form (set as continuous) with a query as the recordsource. The query brings up about 20 questions as records and allows the user to input the answers. Some answers are numeric and I have a numeric field in the underlying table that is displayed on the form as check boxes in a frame. Some questions have textual answers and I have a memo field, displayed as a text box, to capture them. Each question can have only one type of answer so I wish to hide the checkboxes and frame if the answer is textual or to hide the text box if the answer is numeric. I am trying to use the following code:

Private Sub Form_Load()
On Error GoTo PROC_ERR

If [Answer_type] = "T" Then
Me.frameNumber.Visible = False
Me.txtComment.Visible = True
ElseIf [Answer_type] = "N" Then
Me.txtComment.Visible = False
Me.frameNumber.Visible = True
End If

PROC_EXIT:
Exit Sub

PROC_ERR:
MsgBox Err.Description
Resume PROC_EXIT

End Sub

If the Answer_type field in the query is "T" only the text box should show and, conversly, if the Answer_type field in the record is "N", I want only the frame control (with checkboxes) to show.

I seem to get all or nothing (all frame controls or all text boxes). Each form will always have some numeric and some textual questions. Can anyone help? Thanks
 
try placing the same code in the On Current event procedure of the form and see what you get.

 
Yes, Current event should be used here, but the code could be simpler:

Sub Form_Current()
'Me.SomeOtherControl.SetFocus
Me.frameNumber.Visible = ([Answer_type] = "N")
Me.txtComment.Visible= NOT Me.frameNumber.Visible
End Sub

Make sure none of the controls that toggle visibility has the focus when running the code. You may set the focus to another control in the beginning.


HTH


[pipe]
Daniel Vlas
Systems Consultant

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top