473,833 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enable subform based on combo box choice

AccessIdiot
493 Contributor
I have been looking through posts on events happening based on a combo box choice but none really get at the heart of what I am trying to do.

I think this is simple but I'm a newbie so any hand holding and non-startling movements will help here. :-)

I have a form Specimen with a dropdown that displays Species by Species_Code. In the Species table I have a Yes/No field for whether or not the Species is a Fish (Yes = fish). If the user chooses a Species_Code that is a Fish I want the subform to become enabled.

Seems like this is pretty simple but I don't know VB (though I can kind of follow it when I see it written) and am not sure on which event to put this on or how to tie a field from the Species table that isn't being displayed in the dropdown to the subform. Is that confusing?

Basically --> If user chooses a Species_Code that has Fish = yes for that record then subform.visible = true.

Help!
Melissa
Feb 27 '07
26 5694
NeoPa
32,584 Recognized Expert Moderator MVP
I hope I've covered everything, and I'm sorry if I have inadvertently requested any info that is already posted but I missed.
I've also posted 4 times in a row, so don't forget to check them all out and let me know where that leaves you.

Good luck :)
Mar 2 '07 #11
AccessIdiot
493 Contributor
Hey thanks for getting back to me!

I understand Boolean but in my experience Boolean is always 0 or 1 so why -1? That just seems odd to me. But I hear you on ifMyBoolean vs ifMyBoolean = -1 (or whatever value) - that is smarter coding.

Mary actually helped me out with something cleaner and simpler. Here is the code in case anyone else needs it:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSpecies_AfterUpdate()
  2. Dim SpeciesCode As String
  3. Dim aFish As Boolean
  4.  
  5.     SpeciesCode = Me.cboSpecies
  6.     aFish = Me.cboSpecies.Column(2)
  7.  
  8.     If aFish
  9.         Me.sbfrm_FishSpecimen.Visible = True
  10.     Else
  11.         Me.sbfrm_FishSpecimen.Visible = False
  12.     End If
  13.  
  14. End Sub
  15. Private Sub Form_Current()
  16.  
  17.     If Not IsNull(Me.cboSpecies) Then
  18.         cboSpecies_AfterUpdate
  19.     End If
  20.  
  21. End Sub
One thing that would be nice (but isn't totally necessary) is to have the subform set to visible = false when the user goes to a new record. So it doesn't have to wait for another choice from the dropdown to decide whether to be visible or not.

But that's not a necessity - there are bigger fish to fry at the moment!

Thanks again for your help. And for the record, I wasn't really complaining about the lack of help - rather just marveling at how fast a new post gets buried - there are a lot of users on this forum! (which is great by the way).

cheers,
melissa :-)
Mar 5 '07 #12
NeoPa
32,584 Recognized Expert Moderator MVP
I understand Boolean but in my experience Boolean is always 0 or 1 so why -1? That just seems odd to me.
I don't know if you missed that part of my answer (post #9), but at a bitwise level, -1 is just all the bits set to 1. A bit like saying 'All True' if you like. -1 is just the signed integer conversion of a value which is all set to ones. I hope that makes sense.
Mary actually helped me out with something cleaner and simpler. Here is the code in case anyone else needs it:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSpecies_AfterUpdate()
  2. Dim SpeciesCode As String
  3. Dim aFish As Boolean
  4.  
  5.     SpeciesCode = Me.cboSpecies
  6.     aFish = Me.cboSpecies.Column(2)
  7.  
  8.     If aFish
  9.         Me.sbfrm_FishSpecimen.Visible = True
  10.     Else
  11.         Me.sbfrm_FishSpecimen.Visible = False
  12.     End If
  13.  
  14. End Sub
  15. Private Sub Form_Current()
  16.  
  17.     If Not IsNull(Me.cboSpecies) Then
  18.         cboSpecies_AfterUpdate
  19.     End If
  20.  
  21. End Sub
Try out this version :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSpecies_AfterUpdate()
  2.   Call CheckFish()
  3. End Sub
  4.  
  5. Private Sub Form_Current()
  6.   Call CheckFish()
  7. End Sub
  8.  
  9. Private Sub CheckFish()
  10.   Dim blnFish As Boolean
  11.  
  12.   'As a default blnFish starts as False
  13.   If Not IsNull(Me.cboSpecies) Then blnFish = Me!cboSpecies.Column(2)
  14.   Me!sbfrm_FishSpecimen.Visible = blnFish
  15. End Sub
An illustration of how powerful Boolean code can be.
One thing that would be nice (but isn't totally necessary) is to have the subform set to visible = false when the user goes to a new record. So it doesn't have to wait for another choice from the dropdown to decide whether to be visible or not.
Is it a new record in the subform you're talking about or a new record in the main form? We should be able to find a way to implement this. It may mean coding an event in the form that's on your subform but we'll see.
Thanks again for your help. And for the record, I wasn't really complaining about the lack of help - rather just marvelling at how fast a new post gets buried - there are a lot of users on this forum! (which is great by the way).

cheers,
melissa :-)
Oh I see. Buried, as in a long way down the list in the Access forum.
Yes, things do move fast in here. It can be a struggle to keep up sometimes.
Anyway, Pleased to hear you're basically happy.
Mar 5 '07 #13
AccessIdiot
493 Contributor
Are you kidding? I'm incredibly happy. I'm ecstatic. I'm giddy with excitement. I'm actually getting something to work that has no business working because I don't know the code and am basically diving in with lead boots. But thanks to a wonderful community of developers and the internet I'm actually accomplishing something.

I'm going to stop gushing now and try the code you suggested. :-)

Oh and to answer your question its when the main form advances to a new form. Basically when you choose a species from the drop down the subform shows if the species you chose is a fish (I've set up a control so that you can't advance to a new record in the subform, only one subform per main form allowed). When you advance to a new record in the main form the subform is still there, albeit on a new clean record. I'd like it so that the subform disappears when you advance to a new record, sort of starting with a clean plate.

However, after talking with the other person on this project I think we are going to really dumb it down for the users. We're going to hide all the Access built in form buttons (the arrow at the bottom that go to first, last, next, previous and new records) and build in our own with big letters so it is super obvious and they can't accidentally screw things up. :-)

I'm sure when we build the buttons to go to a new record I can program the subform to be not visible again. That would be pretty easy right?

thanks again!
Mar 5 '07 #14
NeoPa
32,584 Recognized Expert Moderator MVP
This all sounds very good, except I am no nearer understanding the answer to my question than I was when I asked it (I'm sure you're trying to be as helpful as you can). Your answer only explains things relative to other things I don't know about. I'm afraid it doesn't take me forward.
Can you try rephrasing your answer in the terms defined by the question (It was formulated specially with that in mind).
I guess that you somehow trigger the opening of another form, but which form and how they're related, is not explained anywhere as far as I can see (I mean in Access terms not from the perspective of the operator, which may have been explained to a certain extent).
Before I can get an idea of what's needed I need a very precise understanding of what's going on.
Is it a separate, unrelated, form (that is opened)?
What are the Record Sources for all the forms and subforms that will pertain in this situation?
Why is the selecting of an item from cboSpecies not an adequate trigger mechanism considering all else that you've explained (which would lead me to conclude that it would be)? Please help me to make more sense of this.
Mar 6 '07 #15
NeoPa
32,584 Recognized Expert Moderator MVP
In case this is not clear, I'm not trying to be grumpy (that just comes naturally), nor am I upset. Simply a bit confused.
Mar 6 '07 #16
AccessIdiot
493 Contributor
Hi NeoPa,

I really appreciate your help and direct questions. I am sorry my answers have been so convoluted. I am learning by fumbling my way through and it is sometimes difficult to comprehend how everything is connected in Access (tables, queries, forms, controls) while teaching myself code that is unfamiliar.

SO - we are going to try a different approach. We are going to remove the standard buttons that Access has on the bottom of all the forms for first/last record, new record, etc and make our own buttons. That way I can put additional code on the button events and that might solve the problem I'm having here.

I'm sure you'll hear from me if I can't get it to work!

thanks again, truly,
melissa :-)
Mar 7 '07 #17
AccessIdiot
493 Contributor
Try out this version :
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboSpecies_AfterUpdate()
  2.   Call CheckFish()
  3. End Sub
  4.  
  5. Private Sub Form_Current()
  6.   Call CheckFish()
  7. End Sub
  8.  
  9. Private Sub CheckFish()
  10.   Dim blnFish As Boolean
  11.  
  12.   'As a default blnFish starts as False
  13.   If Not IsNull(Me.cboSpecies) Then bnlFish = Me!cboSpecies.Column(2)
  14.   Me!sbfrm_FishSpecimen.Visible = blnFish
  15. End Sub
An illustration of how powerful Boolean code can be.
Hey NeoPa I just tried this version and unfortunately it doesn't work. No matter what I choose in the dropdown the subform doesn't show. Maybe I'm not doing something right? Can you explain what it is doing exactly? Maybe I can find the problem.

Also, can you explain to me the difference between using "." and "!" as I see both in different bits of code. As in Me.sbfrm_FishSp ecimen.Visible = False and Me!sbfrm_FishSp ecimen.Visible = blnFish

I'd like to use it though - short and sweet!

thanks much
Mar 7 '07 #18
AccessIdiot
493 Contributor
Never mind! I fixed it - there was a typo with blnFish. I think I understand the code too. Basically, create an integer variable that checks the value of the yes/no column then sets the visibility of the form to that value.

I'd still love to hear an explanation of "." vs "!" though if you have a free moment!

thanks :-)
Mar 7 '07 #19
NeoPa
32,584 Recognized Expert Moderator MVP
Never mind! I fixed it - there was a typo with blnFish. I think I understand the code too. Basically, create an integer variable that checks the value of the yes/no column then sets the visibility of the form to that value.

I'd still love to hear an explanation of "." vs "!" though if you have a free moment!

thanks :-)
For you Melissa - any time :)
Your top explanation is pretty well there :
  1. Check that the cboSpecies control actually has something selected.
  2. Only if so, set the boolean variable blnFish to reflect this from the boolean value in column 2 of cboSpecies.
  3. Set the .Visible property (Also boolean) to the value of blnFish.
'.' Versus '!'
'.' indicates that a (built-in) Property follows.
'!' indicates that a named item in a collection follows.
Object!NameExam ple is technically a shortcut for writing Object.Collecti on("NameExample "). This, in itself is a way of referencing Object.Collecti on(n) where Object.Collecti on(n).Name = "NameExampl e".

I'm not sure about controls on a form.
I've recently been treating them as named items in a Controls collection, but it occurs to me that, while they may not be properties of a Form object exactly, they may well be defined properties of the customised form object that a running form is an instance of.
EG. If you have a form called frmItems then you have created a class object called Form_frmItems in your database. Any instances of this object would have defined (built-in) properties for each of the controls on the form.
If none of this makes sense then ignore it and just stop after ... = "NameExampl e".
Mar 7 '07 #20

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

Similar topics

0
2358
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 to be based on either a View or a Table. I can almost always use a View, and it helps to do this since I can have better control over the size of the RecordSet of the subform. There are times when the use of a Stored Procedure would give me...
1
3487
by: Donna Sabol | last post by:
I have a form (frm_MAIN_RPT) that contains a combo box (Combo6) & subform (dbo_REQ_subform). The combo box is used to select the "cost center" data that will be displayed in the subform. From there, I have a button that runs a report based on which item I select in the subform. 1. The Combo Box correctly displays the list of cost centers within the combo box. 2. The subform, when opened separately, correctly displays the data for the...
0
1160
by: misscrf | last post by:
I have this normalized database, and I don't understand why setting up the forms is so hard for me. I have the main candidate entry form. This is to enter in candidates who apply for a job. I have a tab control with a page that shows if the candidate type is 1 of a few types ( in code). Otherwise 2 pages show. 1 is for contact information. This has an address subform and a phone subform. I can't figure out how to show all address,...
1
2158
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 subform. so you pick a name (in the combo box in the main form) then it should bring up all the dates for which the person has a record for (in the list box or combo box) and then once you pick a date it should bring up the specific record you want...
1
2298
by: MLH | last post by:
I have a form with a subform control on it listing records returned by a saved query named UnbilledVehicles. I would like to put command buttons on the main form to apply dynamic filters to the records displayed in the subform control. Say, for instance, to list only 2004 model cars. I'm seeking the simplest approach. The main form is frmCreateInvoice, the subform control is named frmCreateInvoiceSubFormCtl and the actual sub- form is...
9
9718
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a master-child link to the first subform. subform2 - Master Field: subTrainingModule.Form!TrainingModuleTopicSK Child Field: TrainingModuleTopicSK
2
2017
by: Rex | last post by:
I have a main form and a subform. The main form has a combo box control and the subform has a textfield. What I want to do is when the main form loads it should check the value of the combo box and if it, lets say "MZ" then the textfield in the subform must be enabled otherwise it should be remain disabled. This should be done without setting any explicit focus. Any help would be greatly appreciated.
4
3434
by: JHite | last post by:
I am using Access 2003 on Windows XP. This is a simple database that contains “tblStaffers” containing names of the office staffers, “tblProjects” containing names of the office projects, and “tblStatusReports” containing the “StafferID” (link to Staffer table), the “ProjectID” (link to Projects table), a “Date” field, and a “Notes” field. There is a main form, “frmStaffEntry,” with a subform, “frmStatusReports,” for a user to...
5
2624
by: JHite | last post by:
I’m using Access 2003 on Windows XP. I have a Mainform (Staff Entry) which displays an unbound combo box named ChooseStaff. The Row Source for this combo box is a SELECT of the UserIDs and Staffer Names from a table (Staffers) which contains staffers’ names and other info. When the user actually selects a Staffer Name from the dropdown combo box, the VBA routines for the combo box’s On Enter and After Update events take care of finding and...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10543
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10213
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9323
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7753
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5624
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4422
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.