473,386 Members | 1,883 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.

Problem with numbers

34
Hello,

I'm creating a Project ID and I'm having some trouble getting VBA to respond to correctly. My Project ID has to have 4 digits, so I'm taking the Autonumber ID that Access creates, and adding 0's before depending on how many digits it is.

Here's the code I'm using:
Expand|Select|Wrap|Line Numbers
  1.  iTempID = Me.ID.Value
  2. If iTempID > 999 Then iTempID = iTempID
  3. If 99 < iTempID < 1000 Then iTempID = "0" & iTempID
  4. If 9 < iTempID < 100 Then iTempID = "00" & iTempID
  5. If 10 > iTempID Then iTempID = "000" & iTempID
  6. Me.ProjectID.Value = iTempID
If it is single digit (i.e. <10), it adds the three 0's. However, once it doesn't recognize that it is between 9 and 100, and still adds three 0's. Is there something wrong with my code here? After I wrote this I understood that I could use Len(), but I'd still like to know where I went wrong.

Thanks

Robin
Dec 3 '07 #1
3 1179
Nathan H
104 100+
Hello,

I'm creating a Project ID and I'm having some trouble getting VBA to respond to correctly. My Project ID has to have 4 digits, so I'm taking the Autonumber ID that Access creates, and adding 0's before depending on how many digits it is.

Here's the code I'm using:
Expand|Select|Wrap|Line Numbers
  1.  iTempID = Me.ID.Value
  2. If iTempID > 999 Then iTempID = iTempID
  3. If 99 < iTempID < 1000 Then iTempID = "0" & iTempID
  4. If 9 < iTempID < 100 Then iTempID = "00" & iTempID
  5. If 10 > iTempID Then iTempID = "000" & iTempID
  6. Me.ProjectID.Value = iTempID
If it is single digit (i.e. <10), it adds the three 0's. However, once it doesn't recognize that it is between 9 and 100, and still adds three 0's. Is there something wrong with my code here? After I wrote this I understood that I could use Len(), but I'd still like to know where I went wrong.

Thanks

Robin

What about something as simple as putting "0000" in the format box of the ID field in the table?
Dec 3 '07 #2
Nathan H
104 100+
What about something as simple as putting "0000" in the format box of the ID field in the table?
Try this one...I think there was a problem with using itempID on both sides of the equation I'm not sure. But this was working for me.

Expand|Select|Wrap|Line Numbers
  1. Dim itempID2 As String
  2. itempID = Me.ID.Value
  3. If itempID > 999 Then itempID2 = itempID
  4. If 99 < itempID < 1000 Then itempID2 = "0" & itempID
  5. If 9 < itempID < 100 Then itempID2 = "00" & itempID
  6. If 10 > itempID Then itempID2 = "000" & itempID
  7. Me.ProjectID.Value = itempID2
  8.  
Dec 3 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Nathan

I think your first idea was better. Using format "0000" will show the numbers as the OP requires but will still store them as numbers.

If you try to add trailing 0's to a number it won't work as numbers will always store without them. Whereas the format will show them as required.

Mary
Dec 11 '07 #4

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

Similar topics

33
by: Geoff Berrow | last post by:
I may have mentioned that I run an Introduction to PHP course at a local college (very basic - I'm no PHP expert). Well, one of my students was doing really well so I set him some extension work. ...
10
by: sam | last post by:
hi, i am new to C/C++ and have just finished a program based on the UK national lottery, where you enter 6 numbers, six are generated by the computer and there are appropriate messages and a...
1
by: Emilio | last post by:
(MS Access 2002) Hello, I'm working with some big Census (PUMS) files, and I run into a peculiar problem once the data field exceeds five integers. I'll explain every step, since I am doing it in...
11
by: gouqizi.lvcha | last post by:
Hi all I have a large vector with float point numbers in it, for example (1.1, 2.1 , 3.2 , 3.3 , 4, 6, 3.2, 8). Is there an easy way to determine how many uique elements in the array? Thanks...
10
by: Aravindh | last post by:
A 'C' program that takes two numbers and produces two other numbers. None of the four numbers must be similar. printf ("%d%d", & num1, & num2) ; if (num1 > num2) { num1 ++ ; num2 -- ; } else...
2
by: isetea | last post by:
Hi, I have created a form, which shows values in a combo box and a button with the following code behind: Private Sub Open1_Click() On Error GoTo Err_macro1_Click Dim db As...
4
by: Vlinder | last post by:
I'm completely new to PHP (jumped ship this week from MSAccess and ASP to MySql and PHP) and I'd appreciate some help with leading zeros in telephone numbers. I've got a field with type...
7
beacon
by: beacon | last post by:
I'm writing a program as an assignment that takes 5 sorting algorithms and and tests for the amount of time and the number of comparisons it takes to um, sort an array. I have run into some...
3
by: monkey1001 | last post by:
how do i write a java program tht will store seven integer values in an array of type integer......please helppppp... this is what i got but not sure about it...thnkss...and it has to include reverse...
6
by: fido19 | last post by:
Once upon a time, there lived a chimpanzee called Luycha Bandor (aka Playboy Chimp). Luycha was unhappily married to Bunty Mona, a short but cute little lady chimp. Luycha was tall and handsome –...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.