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

Having trouble using mid function in access 2013

Hi there
I have a 20 character string and I want to get the numbers from position 10 to 14 when they are equal to 5600
I did my access query in design mode as follows but I keep getting syntax errors
NumbA: Mid([fieldname],9,4)
under criteria I put 5600

Could someone please help and tell me what is wrong with that ?
Nov 13 '15 #1
6 1832
hvsummer
215 128KB
== you have wrong criteria..

to get 10 to 14 from string:
Expand|Select|Wrap|Line Numbers
  1. mid(string, 10, 4)
  2.  
but if you want to trap condition, you have to use iif
Expand|Select|Wrap|Line Numbers
  1. iif(mid(string,10,4) like "5600", 5600, string)
  2.  
number inside string is string, so you if put 5600 under criteria, that'll lead you to nowhere since criteria's wrong and data's type wrong.
Nov 13 '15 #2
zmbd
5,501 Expert Mod 4TB
If Paker is only interested in "5600" and not values like "5601" etc, then instead of the Like operand I would use the Equality as the match is specific in nature and will be much faster in data returned.

The only other tweak here is to return either the Null or empty string as the result when the value isn't found at that position as OP only mentioned returning the "5600" value when such is found at that position.

H. didn't mention it; however, you would also use H's solution as a calculated field. The criteria field would not be used with this method.
Nov 13 '15 #3
jforbes
1,107 Expert 1GB
If this is a query, I would go about it a little different to avoid using an iif():
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM SomeTable 
  2. WHERE fieldname LIKE '?????????5600*'
It's not elegant, but I think it will run better/faster.
Nov 13 '15 #4
Thank you all for the suggestions. I will try them out today
Nov 13 '15 #5
zmbd
5,501 Expert Mod 4TB
J, good point and it makes sense if PakerBaker wants the records in their entirety instead of the indicated desired return value of "5600" in the OP. I should have asked about that!
Nov 13 '15 #6
NeoPa
32,556 Expert Mod 16PB
So, there are a number of issues to understand and deal with :
  1. Using Mid() to get the tenth character onwards requires a second parameter of 10 rather than 9.
  2. The returned value of this calculation would be a string, so criteria would have to be a string too.
  3. This can be done using Like in the criteria instead of the Mid() calculation.
  4. A new one - Character positions ten to fourteen would return a five-digit value not a four-digit one.
I'm sure if you deal with all of these issues it'll work fine for you.
Nov 16 '15 #7

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

Similar topics

3
by: Jason | last post by:
I am having trouble using the CONTAINS function in sql server(enterprise manager). I am typing the following: Select * FROM mytable WHERE CONTAINS(myfield,'mystring') This returns the...
1
by: moondaddy | last post by:
I'm running vb.net 1.1 and I need to register a dll using regsvcs.exe and am getting the error: Command "RegSvcs.exe" is not valid. the path to the dll I want to register is: D:\nwis\Apps\CSLA...
1
by: Lauren Wilson | last post by:
I'm having trouble with the Access VBA help on my installation of A2K with Dev tools. Every time I try to retrieve help for items listed in the Object Browser (and SOME other items as well),...
0
by: Eric | last post by:
Hi, I've been trying in vain to get the number of copies a user wants to print after they've closed the PrintDialog form. Apparantly this value is sometimes found in the DEVMODE struct for the...
0
by: RML | last post by:
Hi, I have created a Windows Service which when started, retrieves a file from an FTP server (running W2K Server) via an FTP call. The service is "dependant" on the lanmanworkstation service,...
5
by: tkondal | last post by:
Hi all. I just started looking at Python's ctypes lib and I am having trouble using it for a function. For starters, here's my Python code: from ctypes import*; myStringDLL=...
3
by: Thomas Nelson | last post by:
I'm trying to write a function that uses function pointers. Here's my errors: Board.cc:111: error: expected ',' or '...' before 'p1' Board.cc:111: error: prototype for 'int Board::play_game(int...
2
Ajm113
by: Ajm113 | last post by:
Ok, I want to disable any html tags, but the problem is when I do add in the nl2br function with a htmlentities it displays the tags for the <br>! I even keep seeing rn every time I enter a return in...
6
by: GKJR | last post by:
I have been using Access 2013 (in Office 365) with Windows 8.1 for about a month and a half now. I was a little reluctant to switch from 2010 on Windows 7, but I figured I should try stay ahead of...
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...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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...

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.