Solved

0 prefix gets truncated while reading value from CSV file

Posted on 2004-09-28
8
343 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
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 20 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
 
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now