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

Using "iif" and "between" in vba error

547 512MB
I would like to use the following code in a form with vba, to populate a textbox, but get a compile error: syntax
It seems not to like the "between". This code works 100% in the control source of the textbox.
Any suggestions please? I use Access 2007.
Expand|Select|Wrap|Line Numbers
  1. me.title=IIf(Mid([idno],7,1) Between 0 And 4,"Ms","Mr")
Apr 21 '14 #1

✓ answered by zmbd

personally replace the if then with select

Expand|Select|Wrap|Line Numbers
  1. Select Ch
  2.    case 0 to 4
  3.       me.title = "Ms"
  4.    case >4
  5.       me.title = "Mr"
  6.    case else
  7.       me.title "Err"
  8. end select
  9.  
  10.  
otherwise the same comments as Mr. Ross.

4 1221
Stewart Ross
2,545 Expert Mod 2GB
In VBA you do not have access to statements which work in the query engine. Between is one of them. You also should use a standard IF statement and not an in-line IF. Please note also that Mid is a string function, so the comparison is to the text values '0' and '4'.

Expand|Select|Wrap|Line Numbers
  1. Dim Ch as String
  2. Ch = Mid([idno],7,1)
  3. If(Ch >= '0' And Ch <= '4')
  4.   me.title = "Ms"
  5. Else
  6.   me.title = "Mr"
  7. End If
You may need to refer explicitly to the control containing the [idno] value to make this work - as I don't know which form it is on I can't show the syntax here.
-Stewart
Apr 21 '14 #2
zmbd
5,501 Expert Mod 4TB
personally replace the if then with select

Expand|Select|Wrap|Line Numbers
  1. Select Ch
  2.    case 0 to 4
  3.       me.title = "Ms"
  4.    case >4
  5.       me.title = "Mr"
  6.    case else
  7.       me.title "Err"
  8. end select
  9.  
  10.  
otherwise the same comments as Mr. Ross.
Apr 21 '14 #3
neelsfer
547 512MB
thx Stewart and zmbd its appreciated
Apr 22 '14 #4
zmbd
5,501 Expert Mod 4TB
ahh.. now I wouldn't say I have the best answer as it's the equivalent to Mr. Ross'
It's a prefernce I have and I can see in your code where you might include "Mrs." at some point or perhaps "Mme." etc; thus, the code might be easier to alter in such cases.

I'd also start looking at a recordset/table solution at that point. (^_^)
Apr 22 '14 #5

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

Similar topics

1
by: jgctr4 | last post by:
I'm trying to print an HTML file using AxWebBrowser.ExecWB but it it gives a run time error "Trying to revoke a drop target that has not been registered". Does anyone have any suggestions? ...
5
by: pafgbs | last post by:
I wanted to use some of my MFC stuff in a new C# applikation, so I made an activeX/ocx of my a database viewer. Tested ocx i VB 6.0 and MFC app, worked fine. Tested ocx i a C# .NET app, and upon...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
0
by: Simon | last post by:
I need call a LoginUser API from MC++ dll, but when I try to call the I have always the same exception: "System.NullReferenceException: Object reference not set to an instance of an object. at...
2
by: Howard Kaikow | last post by:
MSFT KB article 302896 includes a step by step example demonstrating how to build an Office COM in VB .NET, Yesterday, I implemented the example and it works correctly when starting each of the...
1
by: thersitz | last post by:
Hi, I am using include statements in my asp.net files as such: <!--#include file="sideBarPartTwo.aspx" --> doing so places an error in my design view of VStudio 2005 -- and then does not...
0
by: ArunkumarSundaravelu | last post by:
Hi I’m creating one windows service in my own purpose Using msxml4.dll. The process of service is to fetch the data from exchange server through webdav SEARCH METHOD When i use this coding...
1
by: Rahul Bhate | last post by:
Hello Sir My problem is in dos giving error that javac is not recognised.Tell me the steps for debugging.I have already set the CLASSPTH through command line & also set the PATH.But still giving...
2
by: mcarthum | last post by:
I have a class declared in a header file as follows: class Vector3{ public: int x,y,z; Vector3(int inx, int iny, int inz); }; And I define the class in a source file:
3
shoonya
by: shoonya | last post by:
Hi, I am having a Microsoft Visual Studio Solution file "abc" present in the folder "foo" having having all the files. Now accidently I did something to the solution file and it's giving...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: 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...

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.