Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010

    Unanswered: Disenabling/Deselecting subform attached to the mainform through a fieldname

    My form [f_farmchar] has a subform [sbf_irrigation] and fieldname [fr_status] attached to it. Now I want the [sbf_irrigation] to be deselected/disenabled if i choose "lowland" and "upland" from its combobox under the fieldname [fr_status]. There are 4 categories to choose from under [fr_status]: lowland, submerged, upland, hilly.

    My purpose is to discontinue the subform [sbf_irrigation] from being added with records when "lowland" and "upland" is chosen from the [fr_status] and continue if otherwise.

    Any help is appreciated. Thank you.

  2. #2
    Join Date
    Dec 2004
    Madison, WI
    If fr_status is a combobox on the main form (f_farmchar), you could set the sourceobject of the subform depending on the value selected like this:

    Private sub fr_status_AfterUpdate()
    if me!fr_status = "lowland" or me!fr_status = "upland" then
    me.sbf_irrigation.sourceobject = "sbf_irrigation"
    me.sbf_irrigation.sourceobject = ""
    end if

    if your combobox is on the sbf_irrigation subform, you can again, set the sourceobject as such...

    Private sub fr_status_AfterUpdate()
    if me!fr_status = "lowland" or me!fr_status = "upland" then
    me.f_farmchar.setfocus <- first setfocus to main form so you can manipulate subform sourceobject
    Forms!f_farmchar!sbf_irrigation.sourceobject = "sbf_irrigation"
    Forms!f_farmchar!sbf_irrigation.sourceobject = ""
    end if

    You'll probably need to add some code though to do something with the record being created on the subform before changing the sourceobject. It depends on how you have it setup.
    Last edited by pkstormy; 05-01-10 at 03:09.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

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