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

if statement with combo boxes on a form

107 100+
Can I write an if statement:
if me.comboOne = "Blue" Then
comboTwo = "small", "medium", and "large"

I know that is not a correct code- but I use if statements to fill textboxes from combo boxes- I am just wondering if I can write an if statement and have a second combo box show the choices I want based off of what the user selects in the first combo box?

thank you
Dec 6 '07 #1

✓ answered by Thembelani Zwan

@missinglinq

this code works perfectly except that one line is missing. Before you can actually us Me.Combo2.RowSource, You need to first specify the Row Source Type (Me.Combo2.RowSourceType) which is Value list since you're manually entering information. The following is the updated code.

Expand|Select|Wrap|Line Numbers
  1. If Combo1 = "blue" Then
  2.     Me.Combo2.RowSourceType = "Value List"
  3.     Me.Combo2.RowSource = "small" & ";" & "medium" & ";" & "large"
  4. Else
  5.     Me.Combo2.RowSource = ""
  6. End If

8 23555
lee123
556 512MB
you could try this:

Expand|Select|Wrap|Line Numbers
  1. if combo1 = blue then
  2.     combo2.text=small", 
  3.     combo2.text="medium", 
  4.     combo2.text= "large"
  5. else
  6.       combo2.text=""
  7.      combo2.text="" 
  8.      combo2.text= ""
  9. end if
lee123
Dec 6 '07 #2
buddyr
107 100+
Thank You,

** the first part of If statement works good but
for some reason I am getting errors with second part after the else **
Dec 6 '07 #3
missinglinq
3,532 Expert 2GB
It's always a good idea to give the version of Access you're running, when asking a question, as it can make a difference! This will do the job in any version of Access, I think.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Combo1_AfterUpdate()
  2. If Combo1 = "blue" Then
  3.  Me.Combo2.RowSource = "small" & ";" & "medium" & ";" & "large"
  4. Else
  5.  Me.Combo2.RowSource = ""
  6. End If
  7. End Sub
  8.  
In the Properties Box - Data for the second Combo2 you have to set Row Source Type to Value List.

Welcome to TheScripts!

Linq ;0)>
Dec 6 '07 #4
buddyr
107 100+
Thanks for explanation and solution
Dec 6 '07 #5
missinglinq
3,532 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. if combo1 = blue then
  2.      combo2.text=small", 
  3.      combo2.text="medium", 
  4.      combo2.text= "large"
  5.  else
  6.        combo2.text=""
  7.       combo2.text="" 
  8.       combo2.text= ""
  9.  end if
There is no way this code could ever work as written.

if combo1 = blue then

blue
is text and would have to be enclosed in quotation marks

combo2.text=small",
combo2.text="medium",

Aside from the fact that small only has quotes on one end, the commas between the assignment statements have no place in Access syntax

Also, you can only use the .Text property if the control in question has focus. Otherwise you have to use the .Value ; Since .Value is the Default Property for a textbox/combobox, you can omit it, i.e.

combo2.Value = "small"

can be simply written

combo2 = "small"


And lastly, if you correct all of the above problems, since you're assigning three values to the combobox value property, only the last value ("large") will be present!

Linq ;0)>
Dec 6 '07 #6
lee123
556 512MB
yea your right when i wrote the code i was in a hurray didn't look at it until now sorry for the bad coding: Missinglinq but thanx for clearing that up.

lee123
Dec 7 '07 #7
@missinglinq

this code works perfectly except that one line is missing. Before you can actually us Me.Combo2.RowSource, You need to first specify the Row Source Type (Me.Combo2.RowSourceType) which is Value list since you're manually entering information. The following is the updated code.

Expand|Select|Wrap|Line Numbers
  1. If Combo1 = "blue" Then
  2.     Me.Combo2.RowSourceType = "Value List"
  3.     Me.Combo2.RowSource = "small" & ";" & "medium" & ";" & "large"
  4. Else
  5.     Me.Combo2.RowSource = ""
  6. End If
Jan 23 '19 #8
twinnyfo
3,653 Expert Mod 2GB
Also, keep in mind that because this is simply a string your re assigning to the value of the RowSource property, there is no need to concatenate. Thus, line 3 above could simply be:

Expand|Select|Wrap|Line Numbers
  1. Me.Combo2.RowSource = "small;medium;large"
However, if one were building this string by other means, using variables, that does demonstrate the ability to concatenate and build an appropriate string.

Thanks for the clarification n this post, Thembelani Zwan!
Jan 23 '19 #9

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

Similar topics

1
by: FZ | last post by:
Hi Gang, I was wondering if a generous person might be able to walk me through what I believe is a pretty simple task. I actually have significant Access experience, but I haven't done it in...
0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
3
by: B | last post by:
I know there are several ways to speed up combo boxes and form loading. Most of the solutions leave rowsource of the combo box blank and set the rowsource to a saved query or an SQL with a where...
3
by: amywolfie | last post by:
Hi All: I would like to run a report based on criteria from 3 unbound combo boxes located on a parameter form (combo boxes are: cboCuisine, cboLocation, and cboRestaurant) The present code...
4
Rabbit
by: Rabbit | last post by:
Cascading Combo/List Boxes This tutorial is to guide you in the creation of Cascading combo/list boxes. That is when you have multiple combo/list boxes where the selection of an option in one...
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
0
by: Dawnyy | last post by:
I have a form which is bound to a dataset. I am filling the forms dataset on Form_Load event. On my form I have combo boxes which I am setting by running a stored procedure to return a datatable,...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.