Results 1 to 10 of 10
  1. #1
    Access_noob is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    12

    Grey out fields in access form depending on field selection on parent form?

    Hi, this is my first time posting to the forum.

    I'm not sure what terminology I should use to find what i am attempting to do. Please bear with me.

    I work for a Power Supply Company.

    I have a Table (customerFaultsTbl). this is for recording customer faults on their household meter.
    I also have PoleFaultsTbl and SubStationFaultTbl.

    I have created a form for the CustomerFaultTbl, and added sub-forms PoleFaults and SubstationFaultsto the parent form.
    So the Subform pole or subStation fault is grabbing the Autonumber from Parent form.

    What i have done is created a lookup Combo Box in the customerFaultsTable labeled FaultType with these options (Meter,pole,subStation)

    1. I would like the form to grey out the 2 sub forms if "meter" is chosen.
    2. If Pole fault is chosen, I would like to grey out meter number on parent from, and Substation Sub-form.
    3. If Substation is chosen, I would like to grey out Meter number on parent form, and Pole sub-Form.


    can someone please advise how i can achieve this, or point me into the correct direction to do so.

    Thank you and much appreciated.
    PS i don't know SQL...

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Code in the combobox AfterUpdate event like:

    Me.Substation.Enabled = (Me.FaultType = "Substation")
    Me.Pole.Enabled = (Me.FaultType = "Pole")
    Me.Meter.Enabled = (Me.FaultType = "Meter")

    Might also want that code in the form OnCurrent event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    As June7 said, the code would definitely need to be in the Form_Current event, of the Main Form, as well as in the AfterUpdate event of the Combobox. The Combobox also has to be Bound to a Field in the underlying Table.

    Also note that the Substation, Pole, and Meter (as in Me.Substation, etc.) has to be the names of the Subform Controls, which may or may not be the same as the names of the Forms that the Subforms are based on. It's the Subform Control that you want to Enable/Disable.

    Linq ;0)>

  4. #4
    Access_noob is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    12

    help compiling the Code.

    Quote Originally Posted by Missinglinq View Post
    As June7 said, the code would definitely need to be in the Form_Current event, of the Main Form, as well as in the AfterUpdate event of the Combobox. The Combobox also has to be Bound to a Field in the underlying Table.

    Also note that the Substation, Pole, and Meter (as in Me.Substation, etc.) has to be the names of the Subform Controls, which may or may not be the same as the names of the Forms that the Subforms are based on. It's the Subform Control that you want to Enable/Disable.

    Linq ;0)>
    Thank you both for having a look...I have tried by myself but still cannot get it to work.
    I get errors when i use the Code listed. I have entered this code into intermediate window.

    Me.Pole_Faults2013.Enabled = (Me.faultType = "pole")

    comes back with an error me.faultType = "pole"
    compile error "method or data member not found"

    Any idea how i can fix???

    This may sound like a silly question, but where can i confirm what the names of Subform Controls are? Poles_Faults2013 is the name of my first sub-form, but it is also the name of a table.
    Please help so that the code takes the user to the correct sub-form or field in the main Form (connection option)??

    Thanks again.

    EDIT

    Hi, ok i altered the Code, i get no errors. But nothing happens now when i select one of the choices in the combobox



    Private Sub Fault_Type_AfterUpdate()
    Me.Pole_Faults2013.Enabled = (faultType = "pole")
    Me.[Sub Fault TBL].Enabled = (faultType = "substation")
    Me.Fault_HVFeeder.Enabled = (faultType = "HV")
    End Sub

    I removed the Me.faultType which removed the compile error, but I am not taken to one of the Sub-forms. after choosing fault type in the combobox.
    I.E. I would like to be taken to a particular Blank field after combobox selection is made.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Select a control and look at its Name property.

    The sub shows name of Fault_Type, not faultType.

    Advise you not use spaces in naming convention. Access will sometimes substitute space with underscore - which possibly why first underscore is in Fault_Type Sub declaration. Elsewhere, must include in brackets: [Fault Type].

    What is the actual field name and what is the actual control name?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    Access_noob is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    12
    Hi June7,

    You are quite right!
    The actual field name is Fault_Type, Fault_type is the control name also.

    Ahh ok its working, i can see that the Label of the subform is being highlighted.
    Thanks!

    Please how can i make the cursor move to a field inside the SubForm?? I may have been a little vague in my OP .
    so once combobox selection is chosen, that the user is taken to the correct field in the sub-form (and one for the main form).

    I have been reading VBA for dummies...i have not quite mastered it yet.

    Appreciate your help


    EDIT: i would like the cursor to be moved to a blank field (new record) depending on the combobox selection....

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    Set focus to the subform container control. The first control in subform's Tab Order sequence should receive focus if Tab Stop is set to yes. Otherwise, code can specify control to get focus.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    Access_noob is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    12
    June7, you are the awesome!
    thanks for quick response.
    kudos, i think i get it now...

    thank you Missinglinq also :-)

    kudos kudos.

    do you mark as solved? or I do?
    lol

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,632
    You can, but already done.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    Access_noob is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Aug 2014
    Posts
    12
    Thanks Mate,

    I actually simplified the code to this...

    Private Sub Fault_Type_AfterUpdate()
    If Me.Fault_Type = "Pole" Then
    Me.Pole_Faults2013.SetFocus
    End If

    I will complete the rest of the options now.
    :-)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-03-2013, 01:20 PM
  2. Replies: 7
    Last Post: 01-17-2013, 07:20 PM
  3. Replies: 5
    Last Post: 08-08-2012, 01:30 PM
  4. Unwanted grey combo box fields on form
    By wouterv81 in forum Forms
    Replies: 1
    Last Post: 04-25-2012, 02:42 AM
  5. Replies: 1
    Last Post: 02-20-2012, 01:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums