Trying to un/hide subform

Niniel

Registered User.
Local time
Today, 17:43
Joined
Sep 28, 2006
Messages
191
Hello,

I already asked this question in the Forms section, but maybe this is a more appropriate venue.

I have a parent table that is linked in a 1->many relationship to the Answers table via RecordID. The Answers table in turn is linked to a Questions table via QuestionID. The Answers table has the following fields - AnswerID (PK), RecordID (FK), QuestionID (FK), Answer [yes/no field].
On a form based on the parent table, I have a subform based on the Answers child table, so that for one record in the parent table, several records from that child table are shown in a continuous subform. They show the text field [the question] and the yes/no field.
What I am trying to figure out is if/how I can create a system so that when one specific checkbox is checked, an action is performed [I want to unhide another subform on the main form that has nothing to do with the Answers table, but is based on another child table].

I was thinking something along these lines might work:

if [Forms]![frmParentForm]![RecordID] and
tblAnswers.QuestionID(99) = true then
subform2.visible = true
else subform2.visible = false [is an else statement always required?]
end if

This is not really an attempt at coding, more an illustration, but the point is that I believe I would have to reference the questionID.

I would greatly appreciate if somebody could help me with the coding here.

Thank you.
 
I had partial success:

Private Sub Answer_AfterUpdate()

If Answer = -1 And QuestionID = 99 Then
Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = True
Else: Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = False

End If

End Sub

When I put this in the AfterUpdate event of the checkbox, I can indeed make my subform visible when I check the second box.

What is not working yet is updating the status as I browse through the records on the main form, or just loading the form.
I've been experimenting with putting the same code in the Current event of the main form, and of the subform, but to no avail yet.
 
It's working now:

Private Sub Answer_AfterUpdate()

If Me.Answer = -1 And Me.QuestionID = 99 Then
Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = True
End If

If Me.Answer = 0 And Me.QuestionID = 99 Then
Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = False
End If

End Sub
_

Private Sub Form_current()

If DLookup("[Answer]", "tblActivityAnswers", "[ActivityID] = " & Forms!frmBrowseApplications![ActivityID] & " AND [QuestionID] = 99") = True Then
Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = True
Else: Forms!frmBrowseApplications!sfrmBrowseSubmissions.Visible = False
End If

End Sub
 
Last edited:
if you are in the parent you can just use the name of the subform on the main form

ie subforma.visible = false

or address a textbox directly as
subformb!textbox1.backcolor=vbred

if you are on one of the subforms, you need to go through the parent
as

me.parent.subformb etc

you can fully specify the syntax if you want but you general;ly don't have to. If you want to set the focus in a subform you may need 2 setfocus events



1 to set focus to the subform
and then another to set the focus in a particular field

ie from the parent

subforma.setfocus
subforma!textbox1.setfocus

if you are still stuck try Access help on
subforms, referring to in expressions
 

Users who are viewing this thread

Back
Top Bottom