Solved

if digit is 1 Or 4 Or 7 Or 0

Posted on 2011-02-10
17
223 Views
Last Modified: 2012-05-11
I am trying the query below but it doesn't work. Can't remember how to do this.

something like this??
If intRDigit = In(1,4,7,0) Then

If intRDigit = 1 Or 4 Or 7 Or 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or 5 Or 8 Then
strtest = "B"
Else
strtest = "C"
End If
0
Comment
Question by:Shawn
  • 6
  • 5
  • 4
  • +1
17 Comments
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 500 total points
Comment Utility
If intRDigit = 1 Or intRDigit = 4 Or intRDigit = 7 Or intRDigit = 0 Then
strtest = "A"
ElseIf intRDigit = 2 Or intRDigit = 5 Or intRDigit = 8 Then
strtest = "B"
Else
strtest = "C"
End If
0
 
LVL 58

Expert Comment

by:cyberkiwi
Comment Utility
You can also use this

If InStr(intRDigit, "1470") > 0 Then
    strtest = "A"
ElseIf InStr(intRDigit, "258") > 0 Then
    strtest = "B"
Else
    strtest = "C"
End If

Open in new window

0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
Or you could use Select Case -

SELECT CASE IntRDigit
   Case 1,4,7,0
      strtest = "A"
   Case 2, 5, 8
      strtest = "B"
   Case Else
      strtest = "C"
End Select
0
 
LVL 58

Expert Comment

by:cyberkiwi
Comment Utility
Or use SELECT CASE

Select Case intRDigit
Case 1, 4, 7, 0
    strtest = "A"
Case 2, 5, 8
    strtest = "B"
Case Else
    strtest = "C"
End Select

Open in new window

0
 
LVL 1

Author Closing Comment

by:Shawn
Comment Utility
brilliant. thank you for the choice :)

Shawn
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
One Line:

strtest = Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B")

mx
0
 
LVL 58

Expert Comment

by:cyberkiwi
Comment Utility
@Dbmx

This is both shorter, and correct, as long as intRDigit is >= 0
Your Choose options don't cover more than 0-8.

strtest = Left(Mid("AABCABCAB", intRDigit + 1, 1) + "C", 1)
0
 
LVL 1

Author Comment

by:Shawn
Comment Utility
i actually used the select case.
the digits are 0-9. the else covers 3, 6 and 9.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Author Comment

by:Shawn
Comment Utility
the actual strings are quite bit longer than strtest = "A".
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"Your Choose options don't cover more than 0-8."
Either does your Accepted solution  - so what?

And your new solution uses two functions instead of 1 !

mx
0
 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
> i actually used the select case.
So then why wasn't there at least a split?  I posted the select case option...
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
"Either does your Accepted solution  - so what?"
Never mind ... I see that it does.  
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
" I posted the select case option..."
Exactly ... First at that ...

mx
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Still one line ... covering any number > 8:

strtest = Nz(Choose(strtest + 1, "A", "A", "B", "C", "A", "B", "C", "A", "B"), "C")

mx
0
 
LVL 1

Author Comment

by:Shawn
Comment Utility
leew
>>So then why wasn't there at least a split?
originally I just tested them and gave out the points to the first correct answer.
afterwards I decided which one to use. sorry about that. If you really want I can see if I can't reopen to distribute the points.
0
 
LVL 75

Expert Comment

by:DatabaseMX (Joe Anderson - Access MVP)
Comment Utility
Just a suggestion ... sometimes it's best to wait for a few posts, especially when it's clear there will be many possible solutions, some simpler than others :-)

mx
0
 
LVL 1

Author Comment

by:Shawn
Comment Utility
good point. thx :)
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now