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

How is it possible to rewrite this code and make it shorter

Hello,
I have an application, which i need to modify, 1 line is really long, so when I add additional condition to it, the program gives an error. I was looking for options to re write it and make it shorter:
Expand|Select|Wrap|Line Numbers
  1.   Me.RecordSource = "SELECT JobOrder.*, IIf([ShipType]=""1"",""ground"",IIf([ShipType]=""2"",""air"")) AS ShipText, IIf([PackType]=""1"",""skid(s)"",IIf([packtype]=""2"",""carton"")) AS PackText, TotalTax, Store.City, Store.PostalCode, Store.StoreName, Int(ReturnMax([weight],[dimweight])+1) AS BillWeight, IIf([ProvinceState].[Region]=""E"",1,IIf([ProvinceState].[Region]=""O"",2,IIf([ProvinceState].[Region]=""U"",3,4))) AS RegionSort, IIf([ProvinceState].[Country]=""CAN"",1,IIf([ProvinceState].[Country]=""USA"",2,3)) AS CountrySort FROM (JobOrder LEFT JOIN Store ON JobOrder.StoreNo = Store.StoreNo) LEFT JOIN ProvinceState ON Store.Province = ProvinceState.StateID WHERE (((JobOrder.JobNo)=[forms]![fdreportjoborder]![jobflt])" & ordflt & ");"
i thought about 'select case', or putting some values into variable, like this :

Expand|Select|Wrap|Line Numbers
  1. TotalTax = ntz([GSTAmount]) + ntz([PSTAmount]) + ntz([HSTAmount]) + ntz([NSHAmount])
But no luck

I'll appreciate your help

thanks

Tali
Aug 4 '10 #1
4 1129
jkmyoung
2,057 Expert 2GB
Create temporary tables:
shiptype(id, type)
1 - ground
2 - air

packtype(id, type)
1 - skid
2 - carton
etc...

and use a join. You will have to be specific about the fields you select though, which is probably better anyways.
Aug 4 '10 #2
thanks for your reply, jkmyoung

i tried it, but guess have some issues with joining the tables. Is it the right way to do so?

Expand|Select|Wrap|Line Numbers
  1.  Me.RecordSource = "SELECT JobOrder.*, temp_shiptype.type AS ShipText, temp_packtype.type AS PackText, ntz([GSTAmount]) + ntz([PSTAmount]) + ntz([HSTAmount]) + ntz([NSHAmount])as TotalTax, Store.City, Store.PostalCode, Store.StoreName, Int(ReturnMax([weight],[dimweight])+1) AS BillWeight, IIf([ProvinceState].[Region]=""E"",1,IIf([ProvinceState].[Region]=""O"",2,IIf([ProvinceState].[Region]=""U"",3,4))) as RegionSort, IIf([ProvinceState].[Country]=""CAN"",1,IIf([ProvinceState].[Country]=""USA"",2,3)) AS CountrySort FROM ((JobOrder LEFT JOIN Store ON JobOrder.StoreNo = Store.StoreNo) left join temp_shiptype on joborder.shiptype=temp_shiptype.id) LEFT JOIN ProvinceState ON Store.Province = ProvinceState.StateID WHERE (((JobOrder.JobNo)=[forms]![fdreportjoborder]![jobflt])" & ordflt & ");"
Thanks
Aug 5 '10 #3
MikeTheBike
639 Expert 512MB
Hi

If you are going to use TotalTax in a query string then I think you need to specifiy the ValueIfNull argument, ie.
TotalTax = ntz([GSTAmount],0) + ntz([PSTAmount],0) + ntz([HSTAmount],0) + ntz([NSHAmount],0)

Even added together this is not a very long string for a query (perhaps the above will fix it?).

With regards to the multiple nested IIf() statements: if the sort order is always the same for Region and Country, I would be tempted add two field the the ProvinceState table (RegionSort and CountrySort and add the sorting values to this and then just Order By these to files in the query.

If fact, on second thoughts, I woud have two separate tables for Region and Country (both with sort order field) and relate then to the StateProvince table (or watever relation conforms to third normal form) and join then to the query to provide both the Region/Counry names and the sort order in the query !!??

Hope that is not too confusing

MTB
Aug 6 '10 #4
Yes, it was confusing.
TotalTax value comes from database as well - to the RecordSource, so I'm not sure how to do that :
TotalTax = ntz([GSTAmount],0) + ntz([PSTAmount],0) + ntz([HSTAmount],0) + ntz([NSHAmount],0)
Do I need another recordsource?

Thanks

N.
Aug 9 '10 #5

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

Similar topics

27
by: Sune | last post by:
Hi! Pre-requisites: ------------------- 1) Consider I'm about to write a quite large program. Say 500 K lines. 2) Part of this code will consist of 50 structs with, say, no more than at most...
1
by: Jignesh Desai | last post by:
There are essentially two ways that you can write code for an ASP.NET application. Inline code Style --------------------------------------------------------------- <html> <script...
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
7
by: vinthan | last post by:
hi, I am new to python. I have to write test cases in python. An application is open in the desk top ( application writen in .Net) I have to write code to get focuse the application and click on...
8
by: mohammaditraders | last post by:
#include <iostream.h> #include <stdlib.h> #include <conio.h> #include <string.h> class Matrix { private : int numRows, numCols ; int elements ;
1
by: vijay1012 | last post by:
How to write code to modify a record. One way is using modify, for example $sqlSession->EditEntity( $objtoedit, "modify" ); But for some reasons i should not use this modify. Is there any way to...
0
by: veron | last post by:
hi. i want to send a sms to activate a device to open or close. can i use vb6 to write code to read sms from GSM modem? and how to use vb6 to write code to read sms from GSM modem?
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?
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
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
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,...

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.