473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Opening a subform based on the option selected in a main form

jinalpatel
I have three option buttons (1 option group): construction projects, non construction projects and aquisition projects.

I have created a form with more than 35 data entry fields for each of this options.ex.frmConstructionProjects,frmNonconstruct ionProj, frmAquisitionProjects

When user selects an option fromm the options group it should open the respective subform.
Expand|Select|Wrap|Line Numbers
  1. Private Sub optProject_Click()
  2. If Me.optProject.Value = 1 Then
  3. DoCmd.OpenForm "frmNonConstructionProj
  4. Else
  5. If Me.optProject.Value = 2 Then
  6. DoCmd.OpenForm "frmConstructionProjects
  7. Else
  8. If Me.optProject.Value = 3 Then
  9. DoCmd.OpenForm "frmAquisitionProjects"
  10. End If
  11. End If
  12. End If
  13. End Sub
  14.  
It opens a new form rather than putting it like a subform under the option group object. How to make it look like a subform which only contains a data respective to the selected option?

Thanks !!
Mar 24 '09 #1
21 6530
ChipR
1,287 Expert 1GB
It sounds like you want to use a Tab control, and put the appropriate data on each tab page.
Mar 24 '09 #2
Thats one way!!
here is some change in req.
I want all those option buttons on main tab. When user selects one of the option the respective subform (or form)should be opened on 11th tab.
The goal here is :Not giving user the access to all the three kinds of prjects type's data entry fields!!
thanks much!!
Mar 24 '09 #3
ChipR
1,287 Expert 1GB
You could have 3 subforms and show/hide them. Or, if the format of the subform is the same, you could just dynamically set the source for a single subform.
Actually, it doesn't seem like you need a subform, just a bunch of controls (data entry fields) that you can hide/unhide.
Mar 24 '09 #4
Where to write the code for show/hide the subform and how?
Is it under the click event of the 11th tab (page)?
something like
Expand|Select|Wrap|Line Numbers
  1. If Me.optProject = 1 Then
  2. Show "frmConstructionProjects"
  3. End If
  4.  
Mar 24 '09 #5
ChipR
1,287 Expert 1GB
I'd probably keep it in the option group's After_Update. Then you won't change it needlessly. You can do:
Expand|Select|Wrap|Line Numbers
  1. mySubform.Visible = True
Mar 24 '09 #6
thanks for the help!!
Mar 24 '09 #7
ChipR
1,287 Expert 1GB
You probably want to set one form to Visible = True, and the other two forms to Visible = False in the AfterUpdate code that you already have. Are there 3 values for your optProjects, because you need a case for each of them.

None of the subforms are going to be visible if the user isn't viewing the tab that they are on anyway, but if you really want to hide them you can watch for the tab control's Change() event, test the value of the tab control to see what # tab is now being viewed, and hide/show things accordingly.
Mar 24 '09 #8
Thanks ChipR for your help!! I appreciate it.
Mar 24 '09 #9
Here is the code if anybody is looking at this thread for help themselves!!
Expand|Select|Wrap|Line Numbers
  1. Private Sub optProjects_AfterUpdate()
  2. If Me.optProjects.Value = 1 Then
  3. frmConstructionProjects.Visible = True
  4. frmNonConstructionProj.Visible = False
  5. frmAquisitionProjects.Visible = False
  6. End If
  7.  
  8. If Me.optProjects.Value = 2 Then
  9. frmNonConstructionProj.Visible = True
  10. frmConstructionProjects.Visible = False
  11. frmAquisitionProjects.Visible = False
  12. End If
  13.  
  14. If Me.optProjects.Value = 3 Then
  15. frmAquisitionProjects.Visible = True
  16. frmConstructionProjects.Visible = False
  17. frmNonConstructionProj.Visible = False
  18. End If
  19.  
  20. End Sub
OR

Expand|Select|Wrap|Line Numbers
  1. Private Sub optProjects_AfterUpdate()
  2. Select Case Me.optProjects
  3.  
  4. Case 1
  5.  
  6. frmConstructionProjects.Visible = True
  7. frmNonConstructionProj.Visible = False
  8. frmAquisitionProjects.Visible = False
  9.  
  10.  
  11. Case 2
  12.  
  13. frmNonConstructionProj.Visible = True
  14. frmConstructionProjects.Visible = False
  15. frmAquisitionProjects.Visible = False
  16.  
  17. Case 3
  18.  
  19.  
  20. frmAquisitionProjects.Visible = True
  21. frmConstructionProjects.Visible = False
  22. frmNonConstructionProj.Visible = False
  23.  
  24. Case Else
  25. frmAquisitionProjects.Visible = False
  26. frmConstructionProjects.Visible = False
  27. frmNonConstructionProj.Visible = False
  28. End Select
  29.  
  30. End Sub
  31.  
I know it is easy but still!!!
Mar 24 '09 #10
I am sorry but I am too impatient..I have one more question regarding the same issue.
When we are going through records using record navigation, it does not change the respective form on 11th tab although it does show (and change it while we are going through records) the option selected previously..
why is that and how to fix it?
Mar 24 '09 #11
ChipR
1,287 Expert 1GB
It sounds like you have one option button and subform for each type of project, so they will both need to be updated in the Form's Current() event.
Mar 24 '09 #12
ChipR
1,287 Expert 1GB
What I mean is, in the Current event, check the project type, then set the optProjects value. Doing this in code probably will not trigger the option group's after update event, but you can call it yourself.
Mar 24 '09 #13
No I have a optionGroup not a single option button. This group has three options and user selects one of them and be able to see the respective form on the 11th tab.
It works very well when we are entering new record. But does not update the form according to the option selected for the previous data.
Sorry I didn't get the part that says to do something with form's current event.
Can u give a little more hint on that, please?
Mar 24 '09 #14
ChipR
1,287 Expert 1GB
I'm not clear on what is supposed to happen when a user moves to another record. Does the subform shown depend on the the option selected only, or on some attribute of the record?
Mar 24 '09 #15
Ya it only depends on the option selected.
The showing of a subform on the 11th tab does not rely on any other attributes but the option button..
Mar 24 '09 #16
ChipR
1,287 Expert 1GB
@jinalpatel
I'm very confused by this. What does not change, what does, what should?
Mar 24 '09 #17
Ok
When the user navigates through records, the records are changed on each and every tab. (normal behaviour)
Here, on the first tab it changes the option automatically but does not change the respective form based on that option on 11th tab.

I think this is the issue of refreshing the data each time user navigates through the records. I need to somehow find the way so that the access refreshes itself and show the respective record on each and every tab.

For example,
On main tab I have three options animals, birds and reptiles. On 11th tab I have data entry filds for their qualities
If I am navigating through the records, and my first record has option selected as Animal, it should show the qualities for animals on 11 th tab.(this should make sense)

But here it shows option selected as animals and qualities (on 11th tab) of birds
(because last time when I left access I entered record which has option selected as birds)
Does this make sense?

If not then it is ok..I need to figure it out somehow!!!!

Thanks!!
Mar 24 '09 #18
ChipR
1,287 Expert 1GB
Just a few more questions, I promise :-]

@jinalpatel
How is this changed automatically? I was under the impression from your other post that the option group and hence the subform were only selected by the user.
Mar 24 '09 #19
ChipR
1,287 Expert 1GB
Do you have a default set for the option group when the form first opens? Try putting this in the Form's Current event:

Expand|Select|Wrap|Line Numbers
  1.    optProjects_AfterUpdate
Mar 24 '09 #20
I think my hard work to explain you worked and it is working with just a single line of code.Perfect!!! Many many thanks to you for helping out..
I just wrote
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. optProjects_AfterUpdate
  3. End Sub
  4.  
Mar 25 '09 #21
ChipR
1,287 Expert 1GB
I'm glad you got it working :)
Mar 25 '09 #22

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: CSDunn | last post by:
Hello, In Access ADP's that connect to SQL Server databases, any time I have a situation where I have a combo box in a main form that looks up a record in a subform, the subform record source has...
1
by: Alienz | last post by:
Alien hello to whoever is reading today. Ill try to explain this as simply as possible its just a weird thing thats happening here in Access 2000 subforms.. I think something small is out of...
25
by: Lyn | last post by:
Hi, I am working on a genealogy form. The only table (so far) lists everybody in the family, one record per person. Each record has an autonum ID. The parent form (frmMainForm) displays the...
2
by: Lyn | last post by:
Hi, I am working on a genealogy project in which I have two tables: Person -- one record for each person in the family. Each record has a unique Autonum field (IDPerson). Partnerships -- one...
1
by: NBruch | last post by:
Ok let me explain what im trying to do: i need a combo box which needs to be linked to a listbox (or combo box doesnt matter which really) then the listbox should bring up the record in a...
9
by: PC Datasheet | last post by:
I'm stuck on something that seems should be easy and I need some help. My main form has an option group with five options. My subform chooses from different lists depending on which option is...
2
by: David W. Fenton | last post by:
I think at various times we've all encountered this problem: A subform is on a main form. From the code of the main form we refer to some property of/control on the child form thus: ...
9
by: natwong | last post by:
Hi All, I'm a newbie in terms of Access and some of its functionality . I've been stuck on this problem for a couple days, even after searching the Web, etc. Currently I have five combo boxes...
1
by: Coll | last post by:
I have a form with a subform on it. On my main form, you select an employee id number and the top portion of form fills in with data, and the bottom portion of the form,which is a subform, lists...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.