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

Select Case Statement not Working Right

this code is not work right with [FirstOffldOperNo] value over 100
could anyone find out what is the problem?
thanks

see code below
Expand|Select|Wrap|Line Numbers
  1. Dim dbs    As DAO.Database
  2. Dim rst    As DAO.Recordset
  3. Dim strSQL As String
  4.   Dim lngrecordcount As Integer
  5. Dim strCurrentOperaNo As String
  6.  
  7. Set dbs = Workspaces(0).OpenDatabase("C:\AccessDBs\Post_Move_Ticket.accdb")
  8.  
  9. strSQL = "SELECT * " & _
  10.              "FROM WODetail"
  11.  
  12.  
  13.             Set rst = dbs.OpenRecordset(strSQL)    'Input Data
  14.  
  15.               'Get a count of the operations
  16.     Set rst = Me!sfrmOpers_InNewTable.Form.RecordsetClone
  17.     rst.MoveLast
  18.     lngrecordcount = rst.RecordCount
  19.  
  20.  
  21.             strCurrentOperaNo = InputBox("Enter Current Operation Number")
  22.  
  23.  
  24.             If IsNull(strCurrentOperaNo) Or strCurrentOperaNo = "" Then 'Nothing entered
  25.             Exit Sub
  26.             End If
  27.  
  28.             Set rst = Me!sfrmOpers_InNewTable.Form.Recordset
  29.             rst.MoveFirst
  30.             Do While Not rst.EOF
  31.             Select Case rst.Fields("FirstOffldOperNo")
  32.  
  33.             Case Is < strCurrentOperaNo
  34.  
  35.             rst.Edit
  36.             rst.Fields("FirstOffldActive") = "0"
  37.             rst.Update
  38.  
  39.             Case Is > strCurrentOperaNo
  40.  
  41.             rst.Edit
  42.             rst.Fields("FirstOffldActive") = "1"
  43.             rst.Update
  44.  
  45.             Case Is = strCurrentOperaNo
  46.  
  47.             rst.Edit
  48.             rst.Fields("FirstOffldActive") = "-1"
  49.             rst.Update
  50.  
  51.             End Select
  52.  
  53.             strCurrentOperaNo = strCurrentOperaNo
  54.  
  55.             rst.MoveNext
  56.  
  57.             Loop
Jul 24 '14 #1
14 2172
Rabbit
12,516 Expert Mod 8TB
It looks like you're working with strings. Convert the values to numbers before comparing them. Otherwise the comparison is on a character by character basis.
Jul 24 '14 #2
the [FirstOffldOperNo]'s data type is "Long Integer", "Dim strCurrentOperaNo As Long Integer" is not taking the data type. Is there a way around it?
Jul 25 '14 #3
Rabbit
12,516 Expert Mod 8TB
What do you mean by "not taking the data type", the phrase is vague.
Jul 25 '14 #4
BikeToWork
124 100+
strCurrentOperaNo is a string in your code, but if you want to declare it as a long integer, first change the prefix to lng then try "Dim lngCurrentOperaNo as Long" Why not have a drop down of CurrentOperaNo values that the user can choose from? That would at least give you a little data validation.
Jul 25 '14 #5
I tried "As Long" or "As Integer" they both get "type mismatch" error. I try to type in "As Long Integer" I get "Compile error: Expected: end of statement"
Jul 25 '14 #6
BikeToWork
124 100+
The InputBox returns a string. Try CLNG() on the string output.
Jul 25 '14 #7
NeoPa
32,556 Expert Mod 16PB
Try these changes :
Expand|Select|Wrap|Line Numbers
  1. Dim lngCurrentOperaNo As Long
  2. ...
  3. lngCurrentOperaNo = CLng(InputBox("Enter Current Operation Number"))
They represent what has already been suggested but maybe you weren't understanding clearly enough.

Obviously, change all other references to the variable in your code in a consistent manner.
Jul 26 '14 #8
thanks to all of you, I did try use CLNG(), it did not work for "Long Integer" data type, what I changed [FirstOffldOperNo]'s data type from "Long Integer" to "Single" and "Dim SigCurrentOperaNo As Single", make both data type the same, and it works good.
thanks again ^_^
Jul 31 '14 #9
NeoPa
32,556 Expert Mod 16PB
Normally, from the info available, I'd expect Long to work better than Single. That is not to say that Single wouldn't work, but simply that it wouldn't be the best approach. To understand why Long doesn't work in your case we'd need access to your project or a better understanding of what you're actually working with.

Frankly, if you're happy with what you have, that's probably not worth the extra effort unless you think so.
Aug 1 '14 #10
Is because [FirstOffldOperaNo] don't need decimals, Long will works faster?
Aug 2 '14 #11
why on the table side, I only have "Long Integer" for data type to pick from the list for "Long", and on the coding side, when I try to "dim" a data type "Long Integer" is not available, only "Long" works, and "Long Integer" is not same data type as "Long" they are "type mismatch", I can not get it work.
Aug 2 '14 #12
NeoPa
32,556 Expert Mod 16PB
In VBA the type name for Long Integer is Long (IE. Long means Long Integer in VBA). This is equivalent to a type of Single which means Single-Precision Floating Point.

As I said in my earlier post, to understand what is wrong in your particular setup (that stops Long from working for you) I would need either :
  1. To be able to look at the project directly.
  2. To have a fuller and clearer explanation from you which included the necessary details.

I would guess the latter is out of the question at this stage as we haven't had that by now. The former can also be quite complicated too, so only consider that if you're particularly interested in getting to the bottom of this.
Aug 2 '14 #13
thanks a lot, I went back to change the data type to Long, and it works this time. It may been something I didn't do right last time when I tried. that's what happen when I try to change too many things at once. from this project, I get to understand more about data type. I am very appreciate all of your help.
Aug 7 '14 #14
NeoPa
32,556 Expert Mod 16PB
MSAccess4Me:
That's what happen when I try to change too many things at once. From this project I get to understand more about data type.
Very wise comment. You're learning - which is always good.

Another very important thing to learn from this exercise is that it never makes sense to panic-change large amounts at one time. Take a step back; Go forward slowly and carefully. Always get one thing done completely and so you're happy with it, before you start the next. Like the tortoise, you'll get there quicker in the long run.
Aug 7 '14 #15

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

Similar topics

8
by: Penny | last post by:
Hi all, My browser throws this Select Case block back at me pointing out a syntax error on the line: 'Case < 251', between the word 'Case' and the '<' symbol. *************************** ...
8
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
11
by: ME | last post by:
In C# the following code generates a compiler error ("A constant value is expected"): public void Test(string value) { switch (value) { case SimpleEnum.One.ToString(): MessageBox.Show("Test...
5
by: PJ6 | last post by:
Select Case o.GetType Case = GetType(SomeRandomTypeName) '... End Select Why doesn't this work? Can I make it work or am I stuck with ElseIf for a long list? Paul
2
by: scole954387 | last post by:
Hi, I have a problem. I have written a SQL statement that has a nested select case statement on the 'where' clause to condition the results. ...
6
by: Spam Catcher | last post by:
Does anyone know why this doesn't work: Select Case X Case X or Y msgbox("hello world!") End Select It seems X or Y doesn't evaluate correctly (I think only the first 1/2 is
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
2
by: csolomon | last post by:
Hello: I am creating a form that will calculate a value based on the value selected from a case statement in a function. The function I created is called GetYield and accepts 3 arguments. I...
3
Seth Schrock
by: Seth Schrock | last post by:
I have recently started using the Select Case function instead of the If Then Else function when there are only two possible values. The reason for this is that I like being able to see what the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.