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

select case not working

35
Hi everyone,

could you please help me. i have a combo box that have the values "1st month", "2nd month" etc, a text box to put details such as weight, length and ccirc. what i want to do is when a user inputs the details and click a button, the text box wres, lres and ccircres will show the results such as "high", "low" or "normal". i tried the following code in the on click event of the button but it wont show anything...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command24_Click()
  2. Select Case Me.age
  3. Case "1st month"
  4.  
  5. ' declares variables
  6.  
  7. If weight <= 2.96 Then
  8. wres = "low"
  9. ElseIf weight >= 4.93 Then
  10. wres = "high"
  11. Else
  12. wres = "Normal"
  13. End If
  14.  
  15. If length <= 49.1 Then
  16. lres = "short"
  17. ElseIf length >= 57 Then
  18. wres = "long"
  19. Else
  20. lres = "Normal"
  21. End If
  22.  
  23. If hcircres <= 34.1 Then
  24. wres = "small"
  25. ElseIf hcircres >= 38.4 Then
  26. wres = "big"
  27. Else
  28. hcircres = "Normal"
  29. End If
  30. End Select
  31.  
  32. Select Case Me.age
  33. Case "2nd month"
  34.  
  35. ' declares variables
  36.  
  37. If Me.[weight] <= 3.57 Then
  38. wres = "low"
  39. ElseIf Me.[weight] >= 5.84 Then
  40. wres = "high"
  41. Else
  42. wres = "Normal"
  43. End If
  44.  
  45. If Me.[length] <= 52.1 Then
  46. lres = "short"
  47. ElseIf Me.[length] >= 60.3 Then
  48. wres = "long"
  49. Else
  50. lres = "Normal"
  51. End If
  52.  
  53. If Me.[hcircres] <= 35.7 Then
  54. wres = "small"
  55. ElseIf Me.[hcircres] >= 39.8 Then
  56. wres = "big"
  57. Else
  58. hcircres = "Normal"
  59. End If
  60. End Select
*its up to 12th months but the code is the same
Apr 23 '11 #1

✓ answered by RuralGuy

Dumb question but you are certain the ComboBox name is age right?

43 3092
RuralGuy
375 Expert 256MB
I would start by only having *one* Select Case...End Select in the procedure.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command24_Click()
  2.    Select Case Me.age
  3.       Case "1st month"
  4.  
  5.          ' declares variables
  6.  
  7.          If Weight <= 2.96 Then
  8.             wres = "low"
  9.          ElseIf Weight >= 4.93 Then
  10.             wres = "high"
  11.          Else
  12.             wres = "Normal"
  13.          End If
  14.  
  15.          If length <= 49.1 Then
  16.             lres = "short"
  17.          ElseIf length >= 57 Then
  18.             wres = "long"
  19.          Else
  20.             lres = "Normal"
  21.          End If
  22.  
  23.          If hcircres <= 34.1 Then
  24.             wres = "small"
  25.          ElseIf hcircres >= 38.4 Then
  26.             wres = "big"
  27.          Else
  28.             hcircres = "Normal"
  29.          End If
  30.  
  31. '----- Remove   End Select
  32.  
  33. '----- Remove   Select Case Me.age
  34.  
  35.       Case "2nd month"
  36.  
  37.          ' declares variables
  38.  
  39.          If Me.[Weight] <= 3.57 Then
  40.             wres = "low"
  41.          ElseIf Me.[Weight] >= 5.84 Then
  42.             wres = "high"
  43.          Else
  44.             wres = "Normal"
  45.          End If
  46.  
  47.          If Me.[length] <= 52.1 Then
  48.             lres = "short"
  49.          ElseIf Me.[length] >= 60.3 Then
  50.             wres = "long"
  51.          Else
  52.             lres = "Normal"
  53.          End If
  54.  
  55.          If Me.[hcircres] <= 35.7 Then
  56.             wres = "small"
  57.          ElseIf Me.[hcircres] >= 39.8 Then
  58.             wres = "big"
  59.          Else
  60.             hcircres = "Normal"
  61.          End If
  62.  
  63.    End Select
  64.  
  65. End Sub
Apr 23 '11 #2
Mac rod
35
hi,
Thanks for the quick reply. i tried it but still it's not showing any values.
Apr 23 '11 #3
RuralGuy
375 Expert 256MB
Put the code in the AfterUpdate event of the ComboBox for more automatic operation. Make sure what is being returned with Me.Age By starting with a MsgBox that displays the value for you as a diagnostic.
Apr 23 '11 #4
Mac rod
35
I put the code in the AfterUpdate event but still won't show any values. Sorry, i'm new to this but how do i make the MsgBox diagnostic?
Apr 23 '11 #5
RuralGuy
375 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command24_Click()
  2.    MsgBox "[" & Me.age & "]"
  3.    Select Case Me.age 
  4.  
Apr 23 '11 #6
Mac rod
35
it returns a message box that says "[]". that's it.
Apr 23 '11 #7
RuralGuy
375 Expert 256MB
That means your Case structure will not work, which is what you are seeing. What is the Bound Column of your ComboBox and what do you have and the RowSource and RowSourceType?
Apr 23 '11 #8
Mac rod
35
RowSource = "1st month";"2nd month";"3rd month";"4th month";"5th month";"6th month";"7th month";"8th month";"9th month";"10th month";"11th month";"12th month";"15th month";"18th month";"24th month"

RowSourcceType = Value List

BoundColumn = 1
Apr 23 '11 #9
Mac rod
35
If it is of any help, i made the combo box by choosing the 2nd option in the wizard something like "i will type the values that i want". then typed it in the form view.
Apr 23 '11 #10
RuralGuy
375 Expert 256MB
Did you move the code to the AfterUpdate event of the ComboBox?
Apr 23 '11 #11
Mac rod
35
yup, still no values and the message box displays "[]"
Apr 23 '11 #12
RuralGuy
375 Expert 256MB
Dumb question but you are certain the ComboBox name is age right?
Apr 23 '11 #13
Mac rod
35
This is embarrassing...
actually it might be the answer! it was unbound and nothing is written in the control source. it's working now. thank you very much!
Apr 23 '11 #14
RuralGuy
375 Expert 256MB
That's Great! Glad we got it working finally.
Apr 23 '11 #15
Mac rod
35
Yes! A really big thanks to you!!! You have been very helpful!
Apr 23 '11 #16
Mac rod
35
hi again, i think this may be a related question since its still the combo box, because when i tested it, the results where all over the place like it would say normal when it shouldn't and sometimes one text box won't display any value at all. i checked the code but it's ok the values are the way they should be. please help.
Apr 23 '11 #17
RuralGuy
375 Expert 256MB
I'm not sure what else I can do with what we have so far. Do you know how to single step the code to see what values are returned and what branches of the code are taken?
Apr 23 '11 #18
Mac rod
35
Hi!
What we have done before solves the problem that i have with the combo box. My problem now is that its not returning the correct values that i set. maybe it have something to do with the code being long and almost the same? about the single step, i don't know how to do that either.
Apr 24 '11 #19
RuralGuy
375 Expert 256MB
While looking at the code you click outside the left margin and a dot appears. That is a BreakPoint. When you run the form and execute the code, it will stop at the BreakPoint. You can then F8 a line at a time and watch the path the code takes. Hovering over variables will pop up their current value.
Apr 24 '11 #20
Mac rod
35
How will i know that its the wrong code? most of them turns yellow when i press F8.
Apr 24 '11 #21
Mr Key
132 100+
Mac, pressing F8 helps runs the code step-by-steps, you just check the results to the end of code! Just Continue and you may know where the code is doing wrong
Apr 24 '11 #22
Mac rod
35
where do i see the results? after running the code step by steps up to the End sub nothing happens.
Apr 24 '11 #23
RuralGuy
375 Expert 256MB
Is the code that sets the other values executing?
Apr 24 '11 #24
Mac rod
35
Yes, but showing other values. like if it should be "normal" it would show "big" or "short" vice versa. And the weight textbox at first it may show for example "low" but if i again click the button it shows "big". and with some values like "60.3" it just won't show anything.
Apr 24 '11 #25
RuralGuy
375 Expert 256MB
Is the right code executing (getting highlighted)? When you hover over weight for example does it display the correct value?
Apr 24 '11 #26
Mac rod
35
Nope. It displays the value that i see in the form which is wrong.
Apr 24 '11 #27
RuralGuy
375 Expert 256MB
You lost me on that one. You enter a value in the weight control and when your code executes and you hover over the weight entry you get the "wrong" value?
Apr 24 '11 #28
RuralGuy
375 Expert 256MB
Maybe you should try and attach you db at this time. Compact and Repair and then ZIP it up first.
Apr 24 '11 #29
Mac rod
35
Yup! From the form view, the value that pops out when i clicked the results button is already wrong, that's the same value that comes when i hover in the code view. Here's my DB, I really appreciate this man.
Attached Files
File Type: zip DBmac.zip (22.8 KB, 111 views)
Apr 24 '11 #30
RuralGuy
375 Expert 256MB
The Name of your control is Combo22. "age" is the field to which that control is bound. The field is not actually updated until you either move to another record or close the form.
Apr 24 '11 #31
Mac rod
35
Yup, when it is in the afetupdate event. but the code is in the button. and if ever it updates it returns the wrong values. Different to those that i wrote on the code.
Apr 24 '11 #32
RuralGuy
375 Expert 256MB
All of the fields in the Development table save two, are text fields. You are doing numerical testing against "text". Your table fields should be probably the Single DataType fields.
Apr 24 '11 #33
Mac rod
35
Actually they were numbers before general number and double. Then i tried text, the results were the same.
Apr 24 '11 #34
RuralGuy
375 Expert 256MB
Try changing them to Single or Double again and see what happens.
Apr 24 '11 #35
Mac rod
35
Still it doesn't show the correct values. have you seen the code? i think i did it correctly? the problem is that for example in the code <= 6.99 should be "short" but after i pressed the button it shows "Normal" or "big". and the thing is "big" is in the other "if" statement.
Apr 24 '11 #36
RuralGuy
375 Expert 256MB
You should name your Controls differently that the fields to which they are bound. Access does not know whether you are referring to the field or the control.
Apr 24 '11 #37
RuralGuy
375 Expert 256MB
See if this "1st Month" works as you would expect.
Attached Files
File Type: zip DBmac1.zip (34.6 KB, 97 views)
Apr 24 '11 #38
Mac rod
35
Actually to all the data i placed there already, the 1st month returns the best answer. Can you try the 2nd month? and also where do i change the control name?
Apr 24 '11 #39
Mac rod
35
the 1st month returns the values correctly now
Apr 24 '11 #40
Mac rod
35
i see the control now i did that also but i didn't change the code. that's why.
Apr 24 '11 #41
RuralGuy
375 Expert 256MB
The name of a control is on the "Other" tab of the property sheet of the control. If you use the Me. preface in the code then Intelisense will show you the possible legal answers.
Apr 24 '11 #42
Mac rod
35
I found it!!! Thanks to you rural guy! I tried and change the 2nd month as well and found that i messed a lot since i only copy, paste and edit it so, it ended up that some of them have the same name. I should be more careful when coding. aside from the fact that i'm using the field name. Thanks a lot again!!!!!
Apr 24 '11 #43
NeoPa
32,556 Expert Mod 16PB
A good point to note here is that if you were in the (good) habit of using capital letters within your object names then the name "age", being all lower-case, would have jumped out as an obvious problem right from the start. It makes sense to use the facilities available to help with your work.
Apr 25 '11 #44

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

Similar topics

17
by: Newbie | last post by:
Dear friends, I am having a hard time understanding how to use a SELECT CASE in ASP. I have used it in VB but never in ASP scripting. Scenerio: I have 2 textboxes on a form that I have to...
9
by: Kevin | last post by:
Hi, I am getting a syntax error Microsoft VBScript compilation error '800a03ea' Syntax error On the code below. The error references the "End Select" line Can anyone help me with what I am...
0
by: aceofhartz | last post by:
hello everyone, i have a multiple choice exam program i am working on and have run into a (hopefully) easy problem. here is my question: i have 4 radiobuttons (bound to an "answercode" field in...
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
3
by: Rob Meade | last post by:
Ok - I *think* this is only different in .net 2.0 - as I've not had any problems in the past, but then maybe I've not tried it... I have a value being read from an xml file where the value maybe...
2
by: gozzer101 | last post by:
Hello all. I have managed to get the select case statements working using the following code: Dim strwhichoption As String strwhichoption = ComboBox1 ComboBox1.AddItem ("Reina")...
12
imrosie
by: imrosie | last post by:
I have a listbox called 'paymnt' ; it has 2 values (check & creditcard). Just below paymnt, I have a command button called 'sendpay' . I am trying to use a Select statement in 'sendpay' based on the...
3
by: CEO123 | last post by:
Does anyone know if it is possible and the syntax to test mutlitple expressions in a select case statement? This is the best I could come up with but it doesn't appear to be working Example: ...
25
by: LBinGA | last post by:
Hello all: I'm having trouble with a nested If Statement working properly. I'm working in MS Access 2002 (OS Windows XP, ver 2002). The non-working code is going on the Form (a Single) as follows:...
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?
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
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...
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.