Results 1 to 9 of 9
  1. #1
    stephanie77 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    14

    Question Combo box selection determines which data entry (new*) subform to open

    Hi



    I desesperately need help on this. I've done lot of research on the net but couldn't find an effecient code that actually works. My database concerns vehicle's manufacturing information and sales follow up.

    I have 2 forms (use as subforms) intend to fill in information on vehicle's major components serial numbers. We have two different types of vehicles : diesel or electric. This characteristic changes the whole manufacturing concept of the vehicle and what components is installed.

    The selection between diesel and electric would be executed with a combo box. Once selected, I want this selection to determine which data entry form (form as new*) will be shown as sub form so I will only have fields really concerning the info I've got to store in the database regarding this specific vehicle.

    Can anyone help me on this matter?

    Thanks in advance!

  2. #2
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    So when the combo says petrol you want one subform. And when you select diesel you want another?


    Sent from my iPhone using Tapatalk

  3. #3
    stephanie77 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    14
    Quote Originally Posted by andy49 View Post
    So when the combo says petrol you want one subform. And when you select diesel you want another?


    Sent from my iPhone using Tapatalk

    Exactly!

    SubFrm_DieselMajorComponents or
    SubFrm_ElectricMajorComponents

  4. #4
    stephanie77 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    14
    Exactly! Either

    SubFrm_DieselMajorComponents or
    SubFrm_ElectricMajorComponents

  5. #5
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    I'd say Change the combo boxes on update event.

    Use an if statement in Code to open the subform you need




    Sent from my iPhone using Tapatalk

  6. #6
    aytee111 is offline Competent At Times
    Windows 7 32bit Access 2013 32bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Use the subform's Visible property - set Me!Subformname.Visible=True/False depending on the combobox value.

  7. #7
    stephanie77 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    14
    Andy : I had this but something's wrong with it, gives me an error

    Private Sub CboChassisType_AfterUpdate()


    Select Case Me.CboChassisType

    If Me.CboChassisType.Value = 1 Then
    SubFrm_DieselMajorComponents.Visible = True
    SubFrm_ElectricMajorComponents.Visible = False
    End If


    If Me.CboChassisType.Value = 2 Then
    SubFrm_DieselMajorComponents.Visible = False
    SubFrm_ElectricMajorComponents.Visible = True
    End If
    End Select
    End Sub


    aytee111 : let me check that

  8. #8
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    try this:

    Code:
    Private Sub CboChassisType_AfterUpdate()
    
    
     Select Case Me.CboChassisType.value
    
    case = 1 
     SubFrm_DieselMajorComponents.Visible = True
     SubFrm_ElectricMajorComponents.Visible = False
    
    
    
    case = 2 
    
     SubFrm_DieselMajorComponents.Visible = False
     SubFrm_ElectricMajorComponents.Visible = True
    
     End Select
     End Sub

  9. #9
    stephanie77 is offline Novice
    Windows 10 Access 2016
    Join Date
    Dec 2016
    Posts
    14
    Thanks a lot Andy for your help ! Aytee your suggestion was in fact part of the solution!

    Just in case anyone would like the same kind of code, here is the final/working code :


    Private Sub CboChassisType_AfterUpdate()


    Select Case Me.CboChassisType.Value


    Case Is = 1
    SubFrm_DieselMajorComponents.Visible = True
    SubFrm_ElectricMajorComponents.Visible = False




    Case Is = 2


    SubFrm_DieselMajorComponents.Visible = False
    SubFrm_ElectricMajorComponents.Visible = True


    End Select


    End Sub



    Also for newbies like me, you put all your subforms in the main form (stacked on each other) and set "visible" property to "no"


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

Similar Threads

  1. Replies: 3
    Last Post: 09-06-2012, 11:01 AM
  2. Replies: 5
    Last Post: 08-08-2012, 01:30 PM
  3. Subform, Combo Box, Data entry
    By hellojosie in forum Access
    Replies: 2
    Last Post: 11-21-2011, 01:29 AM
  4. Combo Box Determines Radio Button Selected
    By sainttomn in forum Forms
    Replies: 5
    Last Post: 08-10-2011, 03:51 PM
  5. referencing subform entry in selection query
    By Pielewuiter in forum Forms
    Replies: 22
    Last Post: 11-20-2010, 01:58 PM

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