M macleod409 Guest Feb 15, 2005 #1 I have to add from 1 - 1999 faster then typing each number in a field. I know how to do it in excel, cant remeber how to do it in access.
I have to add from 1 - 1999 faster then typing each number in a field. I know how to do it in excel, cant remeber how to do it in access.
sfreeman@co.mer Sam_F Local time Today, 15:48 Joined Aug 2, 2004 Messages 272 Feb 16, 2005 #2 If I understand your question, this function will do that... Public Function CountIt() Dim i, c As Long c = 0 For i = 1 To 1999 c = c + i Debug.Print c Next i End Function
If I understand your question, this function will do that... Public Function CountIt() Dim i, c As Long c = 0 For i = 1 To 1999 c = c + i Debug.Print c Next i End Function
J jgc31 Registered User. Local time Today, 23:48 Joined Dec 4, 2004 Messages 78 Feb 16, 2005 #3 Or assuming that the numbers are consecutive and integers Dim intStartNumber, intEndNumber, intLastNumber, intResult as integer intStartNumber = some input say 1 intEndNumber = some input say 1999 intLastNumber = Right("intEndNumber",1) if intLastNumber Mod 2 = 1 then ' checks last digit odd or even ' odd intResult = ( (intStartNumber + intEndNumber) * ( ( intEndNumber -1 )/2 ) ) + ( ( intEndNumber + 1 )/2 ) Else ' even intResult = (intStartNumber + intEndNumber) * (intEndNumber/2) End if This will only give the total but would be much quicker than running a loop.
Or assuming that the numbers are consecutive and integers Dim intStartNumber, intEndNumber, intLastNumber, intResult as integer intStartNumber = some input say 1 intEndNumber = some input say 1999 intLastNumber = Right("intEndNumber",1) if intLastNumber Mod 2 = 1 then ' checks last digit odd or even ' odd intResult = ( (intStartNumber + intEndNumber) * ( ( intEndNumber -1 )/2 ) ) + ( ( intEndNumber + 1 )/2 ) Else ' even intResult = (intStartNumber + intEndNumber) * (intEndNumber/2) End if This will only give the total but would be much quicker than running a loop.
Mile-O Back once again... Local time Today, 23:48 Joined Dec 10, 2002 Messages 11,305 Feb 16, 2005 #4 jgc31 said: Or assuming that the numbers are consecutive and integers Dim intStartNumber, intEndNumber, intLastNumber, intResult as integer Click to expand... You have dimensioned three Variants and one Integer here. Code: Dim intStartNumber As Integer, intEndNumber As Integer Dim intLastNumber As Integer, intResult As Integer
jgc31 said: Or assuming that the numbers are consecutive and integers Dim intStartNumber, intEndNumber, intLastNumber, intResult as integer Click to expand... You have dimensioned three Variants and one Integer here. Code: Dim intStartNumber As Integer, intEndNumber As Integer Dim intLastNumber As Integer, intResult As Integer
Mile-O Back once again... Local time Today, 23:48 Joined Dec 10, 2002 Messages 11,305 Feb 16, 2005 #5 macleod409 said: I have to add from 1 - 1999 faster then typing each number in a field. I know how to do it in excel, cant remeber how to do it in access. Click to expand... But why? You are not using Excel but it sounds as if you are wanting to use Access as if it is Excel - a mistake many people make.
macleod409 said: I have to add from 1 - 1999 faster then typing each number in a field. I know how to do it in excel, cant remeber how to do it in access. Click to expand... But why? You are not using Excel but it sounds as if you are wanting to use Access as if it is Excel - a mistake many people make.