how do i open a subform based on a yes entry in a field in main fo

B

banbloom

I am a new user. I have a yes/no field in a main form/table and I want a
subform to open if 'yes' is clicked on the mainform. Can someone help?
 
G

golfinray

You would need to go into the properties of the checkbox, go to events, go to
the onclick event, click the little button out to the right and start the
code builder. When the code builder comes up, you would need to type
Docmd.openform, "yourformname" and then follow the options.
 
A

Al Campagna

banbloom,
Let's say the checkbox control on your form is named... chkOne, and it
is a boolean field, as you say.
And, your subform name is... frmCheckOneSub

If you use the form Open command, the subform will open in it's own
window, which is not what you want. We'll use the Visible = True/False
property
instead. Make the subform Visible property = to False as the design
default.

In design mode, and viewing the Properties dialog box, and having chkOne
selected...
Locate the AfterUpdate event for chkOne.
Place your cursor in the blank text control.
Using the little arrow on the right, select Event Procedure from
the drop down.
Click the little button on the right with 3 dots (...)
You are now in the form's Module, where VB code can be placed.
You'll see this...

Private Sub chkOne_AfterUpdate()

End Sub

Enter this text between the 2 lines...

Private Sub chkOne_AfterUpdate()
If Check1 = True Then
frmCheckOneSub.Visible = True
Else
frmCheckOneSub.Visible = False
End If
End Sub

*** OR ***

Private Sub chkOne_AfterUpdate()
frmCheckOneSub.Visible = chkOne = True
End Sub

Either coding will show/hide the subform accordingly.

-- hth
Al Campagna
Microsoft Access MVP
http://home.comcast.net/~cccsolutions/index.html

"Find a job that you love... and you'll never work a day in your life."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top