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

subform problem

Status
Not open for further replies.

eggy168

Programmer
Mar 6, 2002
220
US
Hi,
I am trying to add a subform (subfrm1) to my main form (mainfrm1) using one master/child, ID(it is a primary key in the main table). Either the subform or the mainform are coming from the same table but 2 differenct queries
I am wondering is there anyway that I can keep the subform in a hidden mode 'til I click a command button(?) to show it? And the subform will show the same record? Both the subform and the mainform have to do the data entry.
Thanks you.
 
You can hide/show the subform by setting the visible property of the object on the main form.

The code of the button should look something like this:
Code:
<childfield>.visible = True
Where <childfield> is the name of the subform object in the main form.
If you wanted the button to act as a toggle, you can write a simple If..Then statement like this:
Code:
If <childfield>.visible = True Then
   <childfield>.visible = False
Else
   <childfield>.visible = True
End If
When working with subforms, Access will automatically filter the subform to only include records where the master/child link data is the same. So when you view the subform, it should have already selected the record with the same ID.
 
Hi JediMC
Thanks for you reply. I am not sure how to do the procedures..I am a beginner for the Access, don't really know how/where to write the codes...Can you please guide me through?
Thanks
 
To add custom code to your buttons, select the events tab of the properties of the button. In the events tab, find the event you want to capture, in this case the On Click event. Click on the Build button (...) and you will be presented with options for how you would like to build the event action. Select Code Builder and click OK.

This will open the Visual Basic code builder. Access will automatically start you off by starting and ending the Subroutine for you. You should see something like this:
Code:
Private Sub ButtonName_Click()

End Sub
Place the code for the button's action between Private Sub and End Sub lines. Verify that everything is typed correctly and close the Visual Basic code builder.

Make sure that on the properties for the button, next to the On Click event it has a value of [Event Procedure].

Save the form and you should be ready to go!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top