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

enable/disable subform

Status
Not open for further replies.

Kyosa

Technical User
Jun 12, 2000
47
US
i have a form that is comprised of 4 separate subforms. my problem is that the information displayed on one of the subforms is fairly sensitive. i need to set it up such that as a default the sensitive data is disabled unless they enter a pw. then the subform becomes enabled.<br><br>i have tried several variations of this and i always get a reference error saying that the form or subform is not recognized. how do i reference the subform? do i do the form itself or the object on the main form? for some reason if i set the object to disabled the subform displays anyway. and if i set the subform to disabled i can't seem to get it enabled again..&nbsp;&nbsp;AARRGH... maybe i need more coffee!!!<br><br>any ideas on how i might do this would be beyond helpful!!!<br><br>thanks,<br>Kyosa
 
Kyosa,<br><br>Enable the subform or your main form, but don't give it a record source (nothing will show up).&nbsp;&nbsp;After the password is entered correctly, use code on your main form to change the record source of the subform and requery the subform to display the information.&nbsp;&nbsp;<br><br>i.e.&nbsp;&nbsp;if password is correct then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.subformWindowName.recordsource = &quot;formName&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;me.subformWindowName.requery<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end if<br><br>-Chopper<br><A HREF="mailto:kenneth.mai@exch.compass-usa.com">kenneth.mai@exch.compass-usa.com</A>
 
Me![your subform name].Form.AllowEdits = False<br><br>AlsoIn Acess '97<br>If you right click in the VBA code window in click &quot;Build...&quot;<br>It will bring up a dialog box of everything in your database<br><br>double click the forms then find your form<br>double click it then it should show a list of the subforms under it.<br>double click on of them<br>In the middle find a field or what ever<br>the the last list are more items<br>double click in the middle or right lsit and it wil create the exact synatax<br><br>I use it all the time.<br>but they got rid of it in Access '2000. Go figure.<br><br> <p>DougP<br><a href=mailto: dposton@universal1.com> dposton@universal1.com</a><br><a href= > </a><br> Ask me how Bar-codes can help you be more productive.
 
set the form to visible as false<br>put in a command button to view <br>some VBA code like this<br>Private Sub Command2_Click()<br>Dim pword As String, enterstr As String<br>pword = &quot;password&quot;<br>enterstr = InputBox(&quot;Enter password&quot;, &quot;Pass Word is required&quot;)<br>If pword = enterstr Then<br>Me.[Your Form].Visible = True<br>Else<br>MsgBox &quot;Wrong&quot;<br><br>End If<br><br>will want to make a buuton to hide info again also<br>End Sub
 
i must say this forum rocks! thanks alot guys for all your help I got it up and running now just how i want it. Thanks again!!!!
 
just one more ?. if i want to use a custom inputbox (ie my own form) can i still do it the same way as if i would using the InputBox function. <br><br>onlyreason i ask is if i try and use it the same way.. i et an error in my codes saying that the form i'm referenceing is not available ..it may be closed..yada, yada, yada...it doesn't want to let me reference the visible property the same way as if i just used the InputBox function.<br><br>any insights???<br><br>mucho thanks again!!!
 
Just change the code a little. This assumes you opened a completely different form<br>Private Sub Command2_Click()<br>Dim pword As String<br>pword = me.yourform.passwordfield<br><br>If pword = &quot;password&quot; Then<br>forms!Your Form!yoursubform.Visible = True<br>Else<br>MsgBox &quot;Wrong&quot;<br>End If<br><br>to refer to another subform that is open besides the active one <br>use context Forms!yourform!yourSubFRM.Form!fieldname<br>to refer the active form use me.<br><br>to hide the form again you can put a button on the sub form and say me.visible=false<br>or from the form it is a subform on say me.subform.visible= false<br>or to close it from another form that it does not a subform on use context forms!yourform!subform.visile = false<br><br>hope that helps and hope my context is correct! :)<br>Doug did point out a very good way to ensure you refer to a field correctly by using the builder.<br>It gets very confusing.
 
AARGH!!! ok, yet another stupid question. where do i put that code. on the command button (which is where i figured since you had it as a click event) that opens the pw form or elsewhere.<br><br>when i enter it as a click event on the button that opens the custon form it gives me a compile error and says method or data member not found. <br><br>i think i need a beer!!!!
 
just ran a test heres what I did<br>created a form called form1<br>put a subform on it called it mysubform<br>created a 3rd form called form2<br>on form 1 I have a button that opens form2 and mysubform with visible set to false<br>on form 2 I have a text box named password and a command button <br>this code is in form2 command button on click event<br><br>Private Sub Command2_Click()<br>Dim pword As String<br>pword = Me.password<br><br>If pword = &quot;password&quot; Then<br>Forms!form1!mysubform.Visible = True<br>Else<br>MsgBox &quot;Wrong&quot;<br>End If<br>docmd.close<br>End Sub<br>I enter the password and hit submit. form2 closes and I now see mysubform on form1 <br><br>to hide the subform again put a command button on the sub form or on form1 that sets mysubform visible back to false<br>clear as mud &quot;GOOD LUCK&quot;
 
Thanks so much for your help. i had a wee bit of inspiration right after i last posted and figured out to pull it off based on your last post.&nbsp;&nbsp;<br><br>it was pretty similar to your last reply.....again..thanks!<br><br>-Kyosa
 
Glad you got it I saw you went from needing coffee to needing a beer. Once you hit the good stuff, like Jack Daniels, I would have had to join you. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top