473,421 Members | 1,531 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,421 software developers and data experts.

New fields based on combo box selection

Hi everybody! I'm a total newbie at access, just opened it for the first time yesterday so bear with me. I tried a search for my answer and found similar topics but couldn't find the exact answer.

I'm using 2002 Access on XP. In a form, I created a combo box with four different choices. Depending on the selection made I would like a corresponding field to appear. My four selections in the combo box are "Realtor", "Driving", "Mailing", or "Other". If "Realtor" is selected I want a field to appear that asks for the realtor's name and another field that asks for the realtor's phone number. If "Driving" is selected, I want a field to ask for a date. Same for if "Mailing" is selected. If "Other" is selected, I'd like the field to appear where you can enter text to explain.

I have a feeling that the answer lies somewhere under "properties" for my combo box but there is so much in there and it's all over my head. Thanks for any help!
Aug 24 '07 #1
14 1848
in your properties set all of your fields to visible no then for your combo box on the after update even in properties again you'll need a good amount of code like this
If me.ComboName = "Realtor" Then
me.name of textbox.visible = True
else
if me.ComboName = "Whatever" Then
me.Whatever.Visible = True
End If
Hope thats what you were trying to do
Aug 24 '07 #2
Thanks for the suggestion!

I tried it but I couldn't change any of the fields to visible = no. I get an error message that reads "You can't hide a control that has the focus."

What does that mean?
Aug 24 '07 #3
Ferguson,

First of all, the code reads
Expand|Select|Wrap|Line Numbers
  1. .Visible = False
If I were you, I would write nested "If, Then, Else" statements, like the ones already posted, for all four of your choices in the combo box. I would tie each one of those statements to reference the separate text boxes on your form and use the ".Visible = Condition" property in the nested statements to display the appropriate text box on the "AfterUpdate" event of the combo. This should work fine if your typing the code in the correct manner. I'm not sure why you received the error message that you did, but it would lead me to believe that any statement you've written in the module thus far does not contain the correct syntax (sequence of script). Maybe you could post it??
Aug 25 '07 #4
missinglinq
3,532 Expert 2GB
I tried it but I couldn't change any of the fields to visible = no. I get an error message that reads "You can't hide a control that has the focus."
Where were you trying to set the visibilty? The instructions said to set this in the properties box! The control couldn't have focus here! In Design View, select all of the textboxes you want to control the visibilty of. Goto Properties - Form and set the Visibility Property to No. Then try your code in the combobox's afterupdate event.

You'll also have to save one of these 4 designations to each record, and use that (in the Form_Current event) to control visibilty when you return to a record.

We really do need to see the code you've got so far.

BTW, ajetrumpet, Yes/No or True/False will both work with .Visible.

Welcome to TheScripts!

Linq ;0)>
Aug 25 '07 #5
Thanks guys. Sorry I wasn't clear on my earlier post. I didn't try to write any code to turn visible to off. I went to properties for the field as outlined above. The mistake I made was that I wasn't in Design View. Doh! A beginners mistake for sure. I figured it out on my own last night toying around with it.

Ok, after that was fixed, I tried to write some code using the code provided in the first response as a guideline. It worked but there are some bugs that I noticed right away.

1. After making a selection from the combo box in one record, the resulting field appears as it's supposed to, but it shows up in all records instead of just the current one.

2. If I change the selection in the combo box, the field from the earlier selection remains instead of going away.

I'm not a code writer, so I need some help with that! Many thanks!

edit: oops, almost forgot to post my code that I have so far. Here ya go:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Property_Found_By_AfterUpdate()
  2.  
  3. If Me.Property_Found_By = "Realtor" Then
  4. Me.Realtor_Name.Visible = True
  5. Me.Realtor_Phone_Number.Visible = True
  6.  
  7. ElseIf Me.Property_Found_By = "Driving" Then
  8. Me.Driving_Date.Visible = True
  9.  
  10. ElseIf Me.Property_Found_By = "Mailing" Then
  11. Me.Mailing_Date.Visible = True
  12.  
  13. ElseIf Me.Property_Found_By = "Other" Then
  14. Me.Explanation.Visible = True
  15. End If
  16.  
  17. End Sub
Aug 25 '07 #6
I fixed #2 with this code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Property_Found_By_AfterUpdate()
  2.  
  3. If Me.Property_Found_By = "Realtor" Then
  4. Me.Realtor_Name.Visible = True
  5. Me.Realtor_Phone_Number.Visible = True
  6. Me.Driving_Date.Visible = False
  7. Me.Mailing_Date.Visible = False
  8. Me.Explanation.Visible = False
  9.  
  10. ElseIf Me.Property_Found_By = "Driving" Then
  11. Me.Realtor_Name.Visible = False
  12. Me.Realtor_Phone_Number.Visible = False
  13. Me.Driving_Date.Visible = True
  14. Me.Mailing_Date.Visible = False
  15. Me.Explanation.Visible = False
  16.  
  17. ElseIf Me.Property_Found_By = "Mailing" Then
  18. Me.Realtor_Name.Visible = False
  19. Me.Realtor_Phone_Number.Visible = False
  20. Me.Driving_Date.Visible = False
  21. Me.Mailing_Date.Visible = True
  22. Me.Explanation.Visible = False
  23.  
  24. ElseIf Me.Property_Found_By = "Other" Then
  25. Me.Realtor_Name.Visible = False
  26. Me.Realtor_Phone_Number.Visible = False
  27. Me.Driving_Date.Visible = False
  28. Me.Mailing_Date.Visible = False
  29. Me.Explanation.Visible = True
  30. End If
  31.  
  32. End Sub
  33.  
I have no clue on how to fix #1 though. Maybe the answer is what missing said:

"You'll also have to save one of these 4 designations to each record, and use that (in the Form_Current event) to control visibilty when you return to a record."

I don't know what that means though. Can you give a detailed explanation?

Just to be clear, my problem now is the appearance of the fields as I move from record to record. The combo box selection is correctly saved in each record as I leave and come back but the resulting fields are not. For example, if I choose "Driving" from the combo box in record #1 then the field "Driving Date" appears. If I then move to record #2 the field "Driving Date" is still visible even though "Driving" was never selected from the combo box in this record. I hope I explained that well enough. Thanks!
Aug 25 '07 #7
Just wanted to bump up my question just in case it had fallen through the cracks over the weekend.
Aug 27 '07 #8
missinglinq
3,532 Expert 2GB
OK! You say that Property_Found_By is being saved for each record, so now, as you move from record to record, you need to check its value and set the visbility of fields accordingly.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2. If Me.Property_Found_By = "Realtor" Then
  3. Me.Realtor_Name.Visible = True
  4. Me.Realtor_Phone_Number.Visible = True
  5. Me.Driving_Date.Visible = False
  6. Me.Mailing_Date.Visible = False
  7. Me.Explanation.Visible = False
  8.  
  9. ElseIf Me.Property_Found_By = "Driving" Then
  10. Me.Realtor_Name.Visible = False
  11. Me.Realtor_Phone_Number.Visible = False
  12. Me.Driving_Date.Visible = True
  13. Me.Mailing_Date.Visible = False
  14. Me.Explanation.Visible = False
  15.  
  16. ElseIf Me.Property_Found_By = "Mailing" Then
  17. Me.Realtor_Name.Visible = False
  18. Me.Realtor_Phone_Number.Visible = False
  19. Me.Driving_Date.Visible = False
  20. Me.Mailing_Date.Visible = True
  21. Me.Explanation.Visible = False
  22.  
  23. ElseIf Me.Property_Found_By = "Other" Then
  24. Me.Realtor_Name.Visible = False
  25. Me.Realtor_Phone_Number.Visible = False
  26. Me.Driving_Date.Visible = False
  27. Me.Mailing_Date.Visible = False
  28. Me.Explanation.Visible = True
  29. End If
  30.  
Linq ;0)>
Aug 27 '07 #9
Wow, that was a quick response! Thank you missing. I implemented your code and it worked like a charm! Two more quick questions have arisen:

1. What about when the "Property Found By" Combo Box is empty or null? I need to write some code so that in this case, there are no additional fields shown. As it stands now, if I switch the comb box to empty, the fields from the last choice made remain.

2. When you open up that little window where you can write code, there is a dropdown menu in the upperleft (all the fields, form etc) and then a dropdown menu in the upper right that contains all the possible events, I'd like to learn more about all the stuff in these dropdown menus. I never would have been able to find that form_current that you suggested on my own. Perhaps there is a tutorial that explains in detail all the possible choices in these dropdown menus? What each one does etc.
Aug 27 '07 #10
I tried this code for when the combo box is empty but it didn't work:

ElseIf Me.Property_Found_By = "" Then
Me.Realtor_Name.Visible = False
Me.Realtor_Phone_Number.Visible = False
Me.Driving_Date.Visible = False
Me.Mailing_Date.Visible = False
Me.Explanation.Visible = False
Aug 27 '07 #11
missinglinq
3,532 Expert 2GB
Try:

ElseIf IsNull(Me.Property_Found_By) Then
Me.Realtor_Name.Visible = False
Me.Realtor_Phone_Number.Visible = False
Me.Driving_Date.Visible = False
Me.Mailing_Date.Visible = False
Me.Explanation.Visible = False

Linq ;0)>
Aug 27 '07 #12
Perfection! Thank you missing! You were a big time help. I appreciate it.
Aug 27 '07 #13
missinglinq
3,532 Expert 2GB
Glad we could help! As far as the questions about the code window (VBA code editor.)

Select an object from the left hand window, then the right hand dropdown box will offer all the events available for that object. To find out what each event entails, fire up Access Help (I personally whistle for Rocky the Access Hound) and enter the search term Events. Then click on Events and Event Property References and there you have it! A list of all of them. Linq ;0)>
Aug 27 '07 #14
Glad we could help! As far as the questions about the code window (VBA code editor.)

Select an object from the left hand window, then the right hand dropdown box will offer all the events available for that object. To find out what each event entails, fire up Access Help (I personally whistle for Rocky the Access Hound) and enter the search term Events. Then click on Events and Event Property References and there you have it! A list of all of them. Linq ;0)>
Perfect. That should be helpful in the future. Thanks again!
Aug 27 '07 #15

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

Similar topics

3
by: sao | last post by:
I am currently using Access 2000. In my table it is the following fields that are set up: 1 - Staff Name 2 - Department This table is already populated with 100+ records (staff along with...
2
by: news.hp.com | last post by:
I have situation where I need to copy multiple records (only certain fields) from a Rules table to an Events table based on a selection identified in a combo box. When the selection is made in a...
0
by: KB | last post by:
I am creatig a database in 2000 where I need to be able to have the users add data and information into lookup tables. That is no problem, I have a form for that, that works fine. This...
2
by: Cro | last post by:
Dear Access Developers, I am developing a form with 'default view' set to "continuous forms". I am suffering with a problem I can't yet see a solution too. Each record has many fields. Two...
0
by: ISmith | last post by:
Hi, I have two comboboxes on a master form. I need to link them together so that combobox a's on change will update combobox b with maching records and visa versa. Then when a button is...
2
by: Dan Cook | last post by:
Ok... here's the scoop... I've got an unbound form with Serial Number, Building, and Room... all this is in tableA... Now I've got the form setup with building, room and serial number as combo...
1
by: Birderman | last post by:
Hi is it possible to enter data into two separate fields from a single combo box selection. ie if select entry in combo, field 1 will be filled with data from column 1 of combo and field2...
3
by: joseph.mccastlain | last post by:
Hello All, I am a new user to Access. I am currently designing a database consisting of four tables for multiple users. Rather than bore you with the goals and such, here is what I am...
1
by: peasedm | last post by:
Okay this one has me stumped. I have a table called Review_Statements with the following columns: statementid type statement1 statement2 statement3 I have a form called SR_Review with an...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.