[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

0 prefix gets truncated while reading value from CSV file

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
rinksno1
Asked:
rinksno1
1 Solution
 
llcooljayceCommented:
20 points?
0
 
Gruff82Commented:
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
 
Gruff82Commented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
jimbobmcgeeCommented:
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
 
David LeeCommented:
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
 
fds_fatboyCommented:
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
 
jmacmickingCommented:
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
 
rinksno1Author Commented:
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

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now