Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

0 prefix gets truncated while reading value from CSV file

Posted on 2004-09-28
8
Medium Priority
?
351 Views
Last Modified: 2009-07-29
I have a problem in reading a csv file...

I have an employee database in access and an Employee CSV file which is weekly updated.
my application compares an employee id in the csv file with employee id field in the access database( datatype = text in access)...if the employee id is not found in the database then the employee details are inserted into the database....every thing is working fine but when i try compare the employee ID (in CSV file) with first character as zero eg.....02514,02545.... with that in the access database, the zero gets truncated and the employee id value compared is 2514,2545....i want to compare the whole
value i.e. 02514,02545....

what should i do..

rinks
0
Comment
Question by:rinksno1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 4

Expert Comment

by:llcooljayce
ID: 12177071
20 points?
0
 
LVL 4

Expert Comment

by:Gruff82
ID: 12177472
Are your employee ID's set at 5 digits?

If they are you could check the length of id from the csv file and if it is less than 5 pad with zeros.

For example:

if len(csvID) < 5 then
  do while len(csvID) <> 5
0
 
LVL 4

Accepted Solution

by:
Gruff82 earned 40 total points
ID: 12177482
sorry it just went a bit strange then,

what I meant was:

if len(csvID) <5 then
  do while len(csvID) <> 5
    csvID = "0" & csvID
  loop
end if

then compare against your value. I have this problem with Excel to with ISBN numbers but I know a ISBN is 10 digits, so not sure if this will be right for you.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12178022
I find the best way (if a little long winded) is to change the delimeter of the file to a pipe '|' (with a coded Replace statement, if you have to).  You can then load this into Excel as a text file and then use the Text To Columns function in Excel to split it.  When using the TTC function, you can specify the exact format of a column; you should set this to Text to prevent the leading zero being removed.

If you record this TTC function in a macro, you would only need to do it once...

(NB: You may be able to load a .CSV file as a text file and do the TTC routine, if changing the file format to pipe-delimeted is non-viable -- I only use pipe to avoid confusion.)

HTH
0
 
LVL 76

Expert Comment

by:David Lee
ID: 12178347
The only way I can think of that a leading zero would be lost is if the field it's being read into has been declared as numeric.  If that's the case, then there's no way I know of to avoid having that happen.  To retain leading zeros change the field type from numeric to text.
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12178687
similar to  at Gruff82's solution is something like this
Dim EmployeeId As String
...
...

    EmployeeID=Right$("00000" & csvEmployee, 5)
...



Or

...
...
    EmployeeID=Format$(csvEmployee,"00000")

Or

Possibly store the employee number in quotes inside your CSV - "02514","02545"
0
 
LVL 5

Expert Comment

by:jmacmicking
ID: 12181401
How are you reading in the .csv file?

Personally, I'd either:
  Remove the leading zeros in the Access database (assuming they're not significant, ie there would never be an employee with ID 02514 and a different employee with ID 2514)
  Setup a calculated field in an Access query with a calculated field that removes the leading zeros and then base the match on that.
0
 
LVL 3

Author Comment

by:rinksno1
ID: 12187300
Humm...i need to concatinate but i am not comparing the length i am comparing the prefix 2's if it is there then concatinate 0
thankz

rinks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

715 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