Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old October 2nd, 2006, 05:22 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default Zeros at left...

Hello.

Normaly, when we type a number wich the first digit is a 0 (zero) on a cell with "number" as data type, when you hit 'enter' we loose that zero, wright?
Is there a way to keep that zero without changing the data type?
I've tryed changing proprieties but nothing worked.

Please help.
Thanx.

  #2 (permalink)  
Old October 2nd, 2006, 07:46 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

I don't think there is a way to do this. Why do you need to maintain the 0?

If the 0 needs to be there, then this probably isn't really a number data type. Only use a number data type when you need to do arithmetic or mathematic calculations on the field. It sounds like this is used for something else.

Your option is to use two fields:
First field is text field, and the 0 will be preserved.
Second field is number field used for calculations. Hide this field, and populate it from the text field using code "CInt()"

Does this help?


mmcdonal
  #3 (permalink)  
Old October 2nd, 2006, 10:28 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanx mmcdonal.

That can not be done.
There's commercial management program called Winmax that uses an Access table for all the lists(products, clients,...) and I can not "touch it". I tried to change the data type for that ID column and I got an error in the program.
The point is that each client has a code and some of those dodes start with a 0. If I apply it to the software 0's are lost and so it wont match with other programs and tables we work with too.
So I guess there's nothing I can do about it...

Thanx anyway!

  #4 (permalink)  
Old October 2nd, 2006, 10:33 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: Clinton, UT, USA.
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

I'm not sure if this will work, but what about changing the format of the number when it is displayed? if you need a 10 digit number, a mask like "0000000000" should let you keep the leading zeros - at least when it is displayed - it will still store the value in the table as just a regular number sans the leading zeros

Mike

Mike
EchoVue.com
  #5 (permalink)  
Old October 2nd, 2006, 11:18 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Code this, then:

Where sCustID = the string value "0001234"
and iCustID = the number value 1234

If Right(sCustID, Len(iCustID)) = iCustID Then
...
End If

This will compare the two values without the zeroes as used in number fields.

Does this help?




mmcdonal
  #6 (permalink)  
Old October 2nd, 2006, 11:19 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Also, what I was saying before, is accept the number value without the leading zeroes, then display it with them, as Mike suggests.

mmcdonal
  #7 (permalink)  
Old October 2nd, 2006, 11:21 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

Actually, you might have to do this:

If Right(sCustID, Len(iCustID)) = CStr(iCustID) Then
...
End If

Or

Dim sCustID As String
Dim iCustID As Integer
Dim cCustID As String

cCustID = CStr(iCustID)
If Right(sCustID, Len(cCustID)) = cCustID Then
...
End If

I am used to retyping in VBScript, which doesn't work so well in VBA.



mmcdonal
  #8 (permalink)  
Old October 3rd, 2006, 02:27 AM
Authorized User
 
Join Date: May 2006
Location: , , .
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

The masl wont work.
I will work on that condition programing.

Thank you both!



Similar Threads
Thread Thread Starter Forum Replies Last Post
LEFT vs LEFT OUTER joxa83 SQL Server 2005 3 September 18th, 2008 03:13 AM
help with finding zeros of ! ludasky Visual Basic 2005 Basics 1 May 1st, 2008 04:08 PM
Padding Zeros jmss66 Classic ASP Basics 5 January 28th, 2008 07:38 PM
Suppress zeros from displaying smatyk SQL Server 2000 8 October 27th, 2006 08:12 AM
.ToString() functions cuts off zeros olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 2 July 6th, 2004 10:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.