473,398 Members | 2,404 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,398 software developers and data experts.

How do I display Yes/No values based on the format of another (calculated) value

I have a select query with several fields. A calculated field extracts part of the value of one of these fields. I want to retain the extracted value but include a further calculated field that displays Yes or No if the value is in the format LL000000L.

I have tried using the LL000000L in an expression. I have also tried the IiF, AND and RIGHT/MID functions to check all the constituent parts of the value are in the correct format but get stuck on the initial part which could be "AA","AB" etc etc (limited to 255 characters in the expression). The syntax may be incorrect?

I have little knowledge of writing SQL but can understand some, versions are MS Access 2000 v9, Windows XP Prof 2008
Dec 9 '10 #1
7 2489
pod
298 100+
the SQL statement, calculated field, and a bit more details might help (me) to understand a what you are trying to achieve
Dec 9 '10 #2
Here is the SQL statement from View SQL. I have noted the irrelevant fields as Field 1, 2 etc. The calculated field that extracts the part of the value (from the Customer reference field) is marked EXTRACT. There are then 3 separate attempts at a calculated field to check the EXTRACT value is in the LL000000L format (the second try assumes the initial letters are AA or NB, the whole expression actually works but only confirms when that criteris is met - to include all possible values i need to allow for AA-ZZ).

SELECT Dec.[Field 1], Dec.[Field 2], Dec.[Field 3], Dec.[Field 4], Dec.[Customer Reference],

Right([Customer Reference],9) AS EXTRACT,

IIf([EXTRACT].[Format]=[LL000000L],"Yes","No") AS [EXTRACT FORMAT CHECK 2],

IIf(Left([EXTRACT],2) In ("AA","NB") And Mid([EXTRACT],3,6)<999999 And Right([EXTRACT],1) In ("A","B","C"),"Yes","No") AS [EXTRACT FORMAT CHECK],

IIf(Left([EXTRACT],1) In ("A","B","C","D","E","F","G","H","I","J","K","L"," M","N","O","P","Q","R","S","T","U","V","W","X","Y" ,"Z") And Mid([EXTRACT],3,6)<999999 And Right([EXTRACT],1) In ("A","B","C"),"Yes","No") AS [EXTRACT FORMAT CHECK3]
FROM [Dec];
Dec 10 '10 #3
pod
298 100+
The only thing I can suggest is, starts small, i.e. modify your query to its most simple form until it works then add one small change at a time, this way you will be able to find the trouble spot.

Sorry I cannot be more helpful, wish you luck
Dec 10 '10 #4
OldBirdman
675 512MB
I would write a function to return a boolean value. I would put this in my query as:
Expand|Select|Wrap|Line Numbers
  1. SELECT Dec.[Field 1], Dec.[Field 2], ...., 
  2.    blnIsFormatOK(Dec.[Customer Reference]) AS FmtOK, 
  3.    FROM Dec;
The function needs to be Public and NOT in a class module. As a simple example:
Expand|Select|Wrap|Line Numbers
  1. Public Function blnIsFormat(strIn As String) As Boolean
  2. 'There are many ways to write this procedure, using loops and/or Select Case
  3. 'This is a 'brute force' method for illustration purposes
  4.  
  5.     blnIsFormat = True 'Assume Format is correct
  6.  
  7.     If Mid(strIn, 1, 1) < "A" Or Mid(strIn, 1, 1) > "Z" Then
  8.         blnIsFormat = False 'Format is NOT correct
  9.     End If
  10. 'By testing ASC(Mid(strIn, 1, 1)) the upper/lower case could be verified
  11.     ' ......
  12.  
  13.     If Mid(strIn, 3, 1) < "0" Or Mid(strIn, 3, 1) > "9" Then
  14.         blnIsFormat = False 'Format is NOT correct
  15.     End If
  16.     ' ......
  17. 'Further testing could verify the patterns of alpha or numeric
  18. '   to be correct also
  19. End Function 'blnIsFormat
Currently there are no tests for Null, Zero-length, Too long strings, or other expected abnormalities. If the function returned a string, a description of what were wrong could be used, instead of a simple "Yes"/"No"
Dec 10 '10 #5
I was lost at write a function. Perhaps i should have explained that the query was done using the QBE grid. Whilst i understand roughly what the above code does I would struggle writing it.

Guess I may have to see if there are any solutions that can be applied to the QBE grid query. If not I may have a go at it if time allows. Thank you.
Dec 10 '10 #6
OldBirdman
675 512MB
First of all, various sources say the maximum string length is 1,024, 4,096, or 65K+. This should be OK with 1K.
pod's idea that you start slowly and build is a good one. I would start with the first character, which must be between "A" and "Z". I would then have:
Expand|Select|Wrap|Line Numbers
  1. [EXTRACT FORMAT CHECK 2]: IIF(Mid(Dec.[Customer Reference],1,1)>="A" And Mid(Dec.[Customer Reference],1,1) <="Z", "Yes","No") 
in the design grid for the query. I would run this from the design grid until I were satisfied with it.
Next, add the 2nd check, Mid(Dec.[...],2,1) which will add 2 more 'And' clauses to the above grid element. You would have:
Expand|Select|Wrap|Line Numbers
  1. [EXTRACT FORMAT CHECK 2]: IIF(Mid(Dec.[Customer Reference],1,1)>="A" And Mid(Dec.[Customer Reference],1,1) <="Z" And Mid(Dec.[Customer Reference],2,1)>="A" And Mid(Dec.[Customer Reference],2,1) <="Z", "Yes","No")
When this works, add another 'And' for the numeric, which must be >= 0 And <=999999 unless there is an embedded alpha. Proceed in this manner until you have included all your tests within the Iif function.
Another, slightly shorter and probably faster syntax would be:
Expand|Select|Wrap|Line Numbers
  1. [EXTRACT FORMAT CHECK 2]: IIF(Mid(Dec.[Customer Reference],1,1) Between "A" And "Z", "Yes","No") 
Dec 10 '10 #7
Thanks to the comments posted the following formula was constructed and appears to work fine:

(Format) Check: IIf(Left([ref],1) Between "A" And "Z" And Mid([ref],2,1) Between "A" And "Z" And Mid([ref],3,6) Between "000000" And "999999" And Right([ref],1) Between "A" And "Z","OK","INCORRECT")

It checks that the data is in the LL000000L format. All characters are required to be in their respective places, if any letters are entered as numbers (or vice versa) or missed out completely it reports "incorrect".

The letter checks may need to be refined to reflect the true range.

Again many thanks.
Dec 13 '10 #8

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

Similar topics

6
by: Greg | last post by:
I am trying to change the value of one field in my query based on the value in another. If Field 1 had the text "ONACCNT" then in Feild 2 I want the date to change to today's date. Any help would...
3
by: Pavkovich | last post by:
I am setting a yes/no field to identify if the record is open or closed. A yes/no field is either 0 or -1. How do I print the words OPEN or CLOSED on a form based on the yes/no value of the current...
4
by: Santiagoa | last post by:
I have a query with a salary column, this column is used to multiply by a percentage and creates another column with the result. I want to represent the resulting column as currency values. I need to...
2
by: yesgirl | last post by:
Hello, In an Access 2003 form, I have a combo box that offers numerous selections. If certain values are chosen (i.e. "Done") then a date in another field in the form must be entered...
94
by: mlcampeau | last post by:
I have a report (JobVacanciesOnly) that has a subreport (JobVacanciesOnlySR) that are based on two separate queries. MY - JobVacancyJobs SELECT Job.Code, Job.Title, Job.Grade, Grade.Minimum,...
3
by: PowerLifter1450 | last post by:
Hi all, I have to Combo boxes on a form. The first one I would always like users to see. The second, however, I would like hidden if the first box has certain values selected. So, if ComboBox1 has...
2
by: robtyketto | last post by:
Greetings, I have a string element called DeliveryDateTime which stores the date/time as dd/mm/yy hh:mm. I wish to change the hour value based on the value of another string field called...
74
atksamy
by: atksamy | last post by:
1 HI i have database with many tables. In the first table i have a field called status. table 1 idno name status 111 hjghf yes 225 hjgjj no
1
by: srinivas2009123 | last post by:
Hi, I have a class with two Properties like HasSubMenu, and SubMenu , object of this class is bound to property grid. The class is given below. class test { private bool m_HasSubMenu;...
2
by: eihabisaac | last post by:
Hi everyone I'm using VS2005 C# with MySQL to do a windows application i'm also using Devart for MySQL i was able to populate a combobox from the database but i really want to populate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.