Why wont my for loop!

Crash1hd

Registered CyberGeek
Local time
Today, 02:27
Joined
Jan 11, 2004
Messages
143
The following code works fine

Code:
    Dim RaRound
    Dim I
    RaRound = DCount("[Initials]", "Inbound", "[Initials] = [Forms]![Inbound]![Initials]")
    'MsgBox (RaRound)
    For I = 1 To 2'Len(RaRound)
    MsgBox (I)
    Next I

However this doesnt

Code:
    Dim RaRound
    Dim I
    RaRound = DCount("[Initials]", "Inbound", "[Initials] = [Forms]![Inbound]![Initials]")
    'MsgBox (RaRound)
    For I = 1 To Len(RaRound)
    MsgBox (I)
    Next I

Yet if I turn on MsgBox(RaRound) it returns 2???? :confused:
 
Crash,

For i = 1 to RaRound

RaRound has a "value" of 2, don't use its length.

Wayne
 
Oh Duh :rolleyes: lol that explains why no error cause the len(Raround) = 1 lol :) all is much clearer now
Thankyou Thankyou Thankyou! :D :cool:

but why is it doesnt work in this code

Private Sub Prefix_Click()
Dim Test
Test = Me.Prefix
For i = 1 To Len(Test)
If Mid(Test, i, 1) = "1" Then
outputnumber = outputnumber & Mid(Test, i, 1)
End If
Next i
Me.Prefix = outputnumber
End Sub

where test is the input box! and would have something like a phonenumber of (515)-515-5151

and I want to stip it down to just

5155155151 and thats it and maybe have the ability to remove the area code so that its just 5155151
 
Last edited:
Crash,

In the code below, Test is a String.
You can (Should!) go from 1 to its length.

Code:
Private Sub Prefix_Click()
Dim Test
Test = Me.Prefix
For i = 1 To Len(Test)
   If Mid(Test, i, 1) = "1" Then
      outputnumber = outputnumber & Mid(Test, i, 1)
   End If
Next i
Me.Prefix = outputnumber
End Sub

Your code above will only return a string containing all of the "1"s in
Prefix, Or it will return a Null string.

You should see the Help files for input mask. They will let you get what
you visually want, without putting a bunch of "weird" characters in your
data.

Wayne
 

Users who are viewing this thread

Back
Top Bottom