Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Join Date
    Nov 2006
    Posts
    8

    Unanswered: How can you unlock forms with a yes/no question?

    I'm currently designing a database in which only certain subjects may have certain tests. So what I want is a say a yes/no field the form which unlocks the rest of the form so that data can be entered for the applicable data if the answer is yes if the answer is no I would like the form to be either grey out or not present so no data may be entered.

  2. #2
    Join Date
    May 2005
    Posts
    1,191
    Quote Originally Posted by stidyup
    So what I want is a say a yes/no field the form which unlocks the rest of the form so that data can be entered for the applicable data if the answer is yes
    On the click event of a check box, you could do (untested)...
    Code:
    if me.CheckBoxName = False then
         me.ControlName1.visible = false
         me.ControlName2.visible = false
         ...
    else
         me.ControlName1.visible = true
         me.ControlName2.visible = true
         ...
    end if
    for each control on the form.
    This is the brute force method, I think a better method is to set the Tag property for each control in question, then do a For loop testing for the tag property and executing accordingly.


    Quote Originally Posted by stidyup
    if the answer is no I would like the form to be either grey out or not present so no data may be entered.
    You may want to be careful here that the data can still be entered into the table. That is to say, be careful you're not making a required field in the table disapear on the form or something.
    Me.Geek = True

  3. #3
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    You may want to use .Enabled instead of .Visible

    That way, the fields stay on the screen, but become gray and can't be
    updated.
    Inspiration Through Fermentation

  4. #4
    Join Date
    May 2005
    Posts
    1,191
    Quote Originally Posted by stidyup
    I would like the form to be either grey out or not present so no data may be entered.
    Too true Red, but from stidyup's original post, I was thinking he wanted to make them disapear. But I think you're method may work better for him. Either way I guess.
    Me.Geek = True

  5. #5
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    It always seems to take a few posts to find out what they really want.
    Inspiration Through Fermentation

  6. #6
    Join Date
    Nov 2006
    Posts
    8
    Thanks for the tips.

    However I've found another method which is to use a control button to make the form visible after setting the form visible properties to no.

    Private Sub Display_BTM_BL2_Click()

    [Formname].Visible = True

    End Sub

    So far I think this will work.

  7. #7
    Join Date
    Nov 2006
    Posts
    8
    I've ran into a problem with both of the above.

    When I first open the form even though the default is set false none of the fields are greyed out until you tick the box to activate and then click it again to unactivate.

    So far I've got this working in the sense it will deactivate the fields but not when the form is first viewed.

    If EnableFieldsBTM = False Then
    visitdate.Enabled = False
    TRACP5b.Enabled = False
    CathespinK.Enabled = False
    MMP9.Enabled = False
    OPG.Enabled = False
    RankL.Enabled = False
    UrinaryNTXCr.Enabled = False
    UrinaryalphaalphaCTX.Enabled = False
    UrinarybetabetaCTX.Enabled = False
    SerumICTP.Enabled = False
    SerumbetaCTX.Enabled = False
    SerumPINP.Enabled = False
    SerumOsteocalcin.Enabled = False

    Else
    visitdate.Enabled = True
    TRACP5b.Enabled = True
    CathespinK.Enabled = True
    MMP9.Enabled = True
    OPG.Enabled = True
    RankL.Enabled = True
    UrinaryNTXCr.Enabled = True
    UrinaryalphaalphaCTX.Enabled = True
    UrinarybetabetaCTX.Enabled = True
    SerumICTP.Enabled = True
    SerumbetaCTX.Enabled = True
    SerumPINP.Enabled = True
    SerumOsteocalcin.Enabled = True

    End If

    I've tried me.refresh and me.requery as event procedures in on open etc... with no luck. Can anyone offer any suggestions.

    Thanks.

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    In design view set the conrol(s) visible property to false, then when you tick the box you want to enable to controls.
    this will maen initially they'll be greyed out.
    George
    Home | Blog

  9. #9
    Join Date
    May 2005
    Posts
    1,191
    What georgev is totally correct (it's like setting the defaults of the fields to match the default of the check box). But I would like to suggest another alternative. When I'm controlling which fields to show and which not, frequently there are a few different events which could trigger them tripping (in this case, there's Form Open, Check Box On Click, maybe there are others), so I'll frequently create a Private Sub that controls whether the fields are visible/enabled, then call that as necessary.

    Most of the time for a dB, I'll create a form that is used to enter new records. I usually create a sub that controls which of the boxes are required via the tag property. I then can set the required ones' back color to yellow or something and not enable the button until all the required ones are filled in. In this way, I don't have to write the code in 20 different spots, just call it in 20 different AfterUpdate events.

    This may help for you, it may not.
    Me.Geek = True

  10. #10
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Write a function, call a function!
    Saves repeated code and is good practice
    George
    Home | Blog

  11. #11
    Join Date
    May 2005
    Posts
    1,191
    Here's a question for all you awesomely smart types out there:

    I tried writing a Function to do this once, but it wouldn't let me set the visible/enable property inside the function. But I am able to do this from a Sub. Is this the only way to do it or am I just being dumb again?
    Me.Geek = True

  12. #12
    Join Date
    Nov 2006
    Posts
    8
    Thanks for the replies, however when it comes to using the functions behind the scenes I have no understanding of how things work so could you please give an example of the code needed.

    The database I've got displays all forms which can be entered. There is the main form (with base data ie study number and initials) onto which there is a tabbed form for each visit week eg Week 1, Week 4, Week 12 etc.... On each tab there is a subform relating to the respective week, which then has another tab form for the test results for that visit.

    See uploaded jpg.

    Also where is the conrol(s) visible property to false? The only property that mentions control is "control box" or does this need to be entered in as an event procedure?

    The reason why I prefer tabs is that it saves going in and out of forms, if you have ever needed to actually enter information into a database you may understand how frustrating it is constantly having to click in and out of forms needlessly.
    Attached Thumbnails Attached Thumbnails Database.jpg  
    Last edited by stidyup; 02-12-07 at 05:59.

  13. #13
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Quote Originally Posted by stidyup
    Also where is the conrol(s) visible property to false?
    "Control" is a word used to describe textboxes, checkboxes, listboxes, comboboxes etc..

    if you don't understand functions then the simplest answer would be:
    repeated code wherever you need it.

    As for tabs... They're good in moderation but can so easily become incredibly confusing if they are over/misused. I rarely have any more than 4 tabs on any single form - purely because fom a users perspective too much information at one time can blow their tiny minds
    George
    Home | Blog

  14. #14
    Join Date
    May 2005
    Posts
    1,191
    Based on your earlier post, try the following:

    Replace your code with
    Code:
    Call EnableFields
    Then at the end of your vb module (the screen with all the code), paste the following:
    Code:
    Private Sub EnableFields
    
    If EnableFieldsBTM = False Then
    visitdate.Enabled = False
    TRACP5b.Enabled = False
    CathespinK.Enabled = False
    MMP9.Enabled = False
    OPG.Enabled = False
    RankL.Enabled = False
    UrinaryNTXCr.Enabled = False
    UrinaryalphaalphaCTX.Enabled = False
    UrinarybetabetaCTX.Enabled = False
    SerumICTP.Enabled = False
    SerumbetaCTX.Enabled = False
    SerumPINP.Enabled = False
    SerumOsteocalcin.Enabled = False
    
    Else
    visitdate.Enabled = True
    TRACP5b.Enabled = True
    CathespinK.Enabled = True
    MMP9.Enabled = True
    OPG.Enabled = True
    RankL.Enabled = True
    UrinaryNTXCr.Enabled = True
    UrinaryalphaalphaCTX.Enabled = True
    UrinarybetabetaCTX.Enabled = True
    SerumICTP.Enabled = True
    SerumbetaCTX.Enabled = True
    SerumPINP.Enabled = True
    SerumOsteocalcin.Enabled = True
    
    End If
    
    End Sub
    The on the On Open event of your form, do a similar call to above, id est:
    Code:
    Call EnableFields
    This is what is meant by calling a sub as needed. Now you can call this sub whenever else you want as well.
    Me.Geek = True

  15. #15
    Join Date
    Nov 2006
    Posts
    8
    Thanks for the info, I'll try the code later and let you know how I get on.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •