Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2002
    Posts
    13

    Question Unanswered: Form Field Visibility

    Hi,

    Is there a way to set the enable or visible property (or dim the field) of a form text field based on a value from another linked table without knowing VB?

    Thanks,

    Luis.

  2. #2
    Join Date
    Jan 2003
    Location
    Aberdeen, Scotland, UK
    Posts
    168
    The only way I'm aware of is with VB. It would be a simple line of code though. I you post the names of all the fields and tables etc. I (or someone else) would easily write the code for you.

  3. #3
    Join Date
    Nov 2002
    Posts
    13
    Thanks for the reply.

    There is a TiAsD table with 12 registers. There is a SomeForm with seven fields. Register 6 (value 6) of TiAsD table allows entrances on the first, third and fifth field of SomeForm and dims the second, fourth, sixth and seventh fields of SomeForm. With this I can guess the rest.

    Thanks Again,

    Luis.

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    try the following:

    a form with boxes for all your registers (here i call the boxes reg1, reg2, reg3 etc, but modify to suit whatever you call them in designView-properties-other-name. the name shows up in a box under the file menu top left of the screen when you click a box in designView).

    add a button to your form (i call it butQuit)

    your code looks something like this:
    Code:
    Private sub Form_Current()
    
      'set focus away from my boxes to be on the safe side
      butQuit.setfocus
    
      'disable all boxes
      reg1.enabled = false
      reg2.enabled = false
      reg3.enabled = false  'repeat this for each box through to...
      reg12.enabled = false
     
      'now enable selected boxes depending on the values in some boxes
      if reg6.value = WhateverValueInReg6SwitchesOnSomeBoxes
        reg1.enabled = true
        reg3.enabled = true
        reg5.enabled = true
      end if
    
    end sub
    WhateverValueInReg6SwitchesOnSomeBoxes needs to be replaced to suit what you've got in Reg6:
    if it's a Yes/No: True (or False, whatever is your "on" value)
    if it's a text: "Switch 1,3,5 on" (or whatever is your "on" text in quotes)
    if it's a number: 72 (or whatever is your "on" value)

    _Current may not be the event that suits you
    cut/paste the same code to _Load or other Form events to check out the behaviour.

    .enabled may not be the effect you are looking for
    replace all occurances of .enabled with .visible or .locked to check out the behaviour

    maybe you also should set some/all boxes designView-properties-format-visible-false so they start off invisible when the form first loads.

    izy
    Last edited by izyrider; 04-03-03 at 14:12.

  5. #5
    Join Date
    Nov 2002
    Posts
    13
    Thanks, but I think this may be simpler than that.

    I have 7 fields at a form. One per weekday. Each field should be enabled or not depending on one of 12 values at another table. The 7 weekday table has a foreign key to the 12 value table. So I imagine a code for enabling or not each of the 7 fields. This code will have 12 lines, each line to check one possible value of the other (mother) table. What I do not know is how and where to put this enabler code at each of the seven fields at the form.

    Thanks again and greetings from Brazil.

    Luis.

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i guess you have a query that pulls records from your mother table and the weekday table, and you have a form that displays all of this data.

    i've no idea what your fields & text boxes are called or what data is in them, so i make the following assumptions:
    field Mother6 is Yes/No and appears on your form in a checkbox Tick6
    you daily data is in text boxes called Day1, Day2.......
    you will have to change the box names in the code below to suit your reality.

    when Mother6 = TRUE you want Day1, Day3, Day7 enabled, the other DayX disabled.


    Menu:View¦Code your form and at the end of any text that is already there, add a couple of line-feeds and type:

    Code:
    Private sub Luis()
    
    	'move focus somewhere harmless
    	Tick6.SetFocus
    
    	'disable all DayX boxes
    	Day1.Enabled = False
    	Day2.Enabled = False
    	Day3.Enabled = False
    	Day4.Enabled = False
    	Day5.Enabled = False
    	Day6.Enabled = False
    	Day7.Enabled = False
    
    	'selectively enable some DayX boxes
    
    	If Tick6.Value = True Then	'Mother6 switches on Day1, Day3, Day7
    		Day1.Enabled = True
    		Day3.Enabled = True
    		Day7.Enabled = True
    	End If
    
    	If Tick3.Value = True Then	'Mother3 switches on Day2
    		Day2.Enabled = True
    	End If
    
    End Sub
    you now have a subroutine that selectively enables DayX boxes - next task is to decide when it should run. i don't know what you are trying to do, so below are three example events that call your subroutine.

    still in the code window of your form, find the "object" combo top-left and select Form. mr gates has decided that this will automatically generate an empty subroutine Form_Load - you will add some text in the middle of this empty subroutine.

    Code:
    Private Sub Form_Load()
    
    	'delete the next line once things are working for you
    	msgbox "Form_Load event is about to call Luis"
    
    	Luis
    
    End Sub
    in the top-right combo of the code window, select Current. an empty subroutine Form_Current appears in the code window - add some text in the middle:

    Code:
    Private Sub Form_Current()
    
    	'delete the next line once things are working for you
    	msgbox "Form_Current event is about to call Luis"
    
    	Luis
    
    End Sub
    in the top-right combo of the code window, select AfterUpdate. an empty subroutine Form_AfterUpdate appears in the code window - add some text in the middle:

    Code:
    Private Sub Form_AfterUpdate()
    
    	'delete the next line once things are working for you
    	msgbox "Form_AfterUpdate event is about to call Luis"
    
    	Luis
    
    End Sub

    yes... all these msgboxes will quickly drive you mad, but you will at least see the events occuring. which event or events you use depends on what you are tying to achieve - there are hundreds of possible events --- if you want something more specific, post your mdb and someone will help you out.

    izy

  7. #7
    Join Date
    Nov 2002
    Posts
    13
    Ok, so here it goes:

    The decision table is not a checkbox table. It is a value table.

    Table TiAsD is the code of the subscription. If a plan is for a Mon - Wed - Fri (TiAsD = 6) subscription then the customer will be able to fill Three addresses, End2 (monday delivery address), End4 (wed) and End6 (fri).

    CodTiAsD Description Addresses Enabled:
    1 1 Monday End2
    2 2 Tuesday End3
    3 3 Wednesday End4
    4 4 Thursday End5
    5 5 Friday End6
    6 6 Mon, Wed, Fri End2, End4, End6
    7 7 Tues, Thurs End3, End5
    8 8 Mon to Fri End2, End3, End4, End5, End6
    9 9 Saturday EndS
    10 10 Sunday EndD
    11 11 Saturday + Sunday EndS, EndD
    12 12 Daily all seven addresses


    Table/Form AsDF will be used to populate seven addresses tables, one per weekday. The form has the 7 text boxes for the addresses:

    End2
    End3
    End4
    End5
    End6
    EndS
    EndD

    Table AsDF has a FK field CodTiAsD, and depending on the value, will enable the selected address fields. I understand I will code the AsDF form as follows:

    Private sub Luis()

    'move focus somewhere harmless
    Tick6.SetFocus

    'disable all DayX boxes

    End2.Enabled = False
    End3.Enabled = False
    End4.Enabled = False
    End5.Enabled = False
    End6.Enabled = False
    EndS.Enabled = False
    EndD.Enabled = False

    'selectively enable some EndX boxes

    If [TiAsD].CodTiAsD = 6 Then
    End2.Enabled = True
    End4.Enabled = True
    End6.Enabled = True
    End If

    If ...
    'This way I will have the 12 if then
    End If

    End Sub

    Now the question: Where goes Sub Luis? BeforeInsert event of the ASDF form? Does the foreign key of the AsDF table grant the recognition of the [TiAsD].CodTiAsD value?

    Thanks,

    Luis.

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry for the delay - been busy.
    it is easier to do than to explain - see if the attached example helps.

    izy

Posting Permissions

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