Do Loop not working or passing back variable (1 Viewer)

Adrianna

Registered User.
Local time
Today, 16:27
Joined
Oct 16, 2000
Messages
254
Obviously I have don't something wrong because I'm not getting the number to increment. Doesn't Order By sort in ascending order? If so, then why does this note work and why is the value not being passed back to the form?

PHP:
If IsNull(LocationID) Then
    MsgBox "You must provide an Location ID", vbExclamation, "Missing Entry"
Else
    If IsNull(Type) Then
    MsgBox "You must provide an Node Type", vbExclamation, "Missing Entry"
    Else
             
        Set rst = dbITArchitectureData.OpenRecordset( _
        "SELECT *" & _
        " FROM tNeedLines" & _
        " WHERE LocationID =" & Forms!FrmAddNeedlinesWithMapping!LocationID & " AND Type = '" & Forms!FrmAddNeedlinesWithMapping!Type & "'" & _
        " ORDER BY mappingID", dbOpenDynaset)
      
        If Type = "NON TRADOC Node" Then
        mapId = 1
        Else
        mapId = 42
        End If
         
        With rst
            Do While MappingID <> mapId
            mapId = mapId + 1
            Loop
        MsgBox ("MapId is equal to " & [mapId]) ' looking at value
        mapId = Forms!FrmAddNeedlinesWithMapping!MappingID
        End With
    rst.Close
    End If
End If
 

ecniv

Access Developer
Local time
Today, 21:27
Joined
Aug 16, 2004
Messages
229
you forgot the .movenext inside the loop?
Also what happens if it doesn't match - inifinite loop?

What are you trying to do here in the code?


Vince
 

Adrianna

Registered User.
Local time
Today, 16:27
Joined
Oct 16, 2000
Messages
254
:confused:
Hehe...I had a Do Until <> before I got the "too few parameters" error and made a lot of changes. Luckily I fixed the parameters error.
...GOES TO TRY CHANGING IT BACK...

Okay....
I've changed it to:
With rst
Do While Not .EOF
If rst.Fields!MappingID.Value = mapId Then
mapId = mapId + 1
Else
.MoveLast
Forms!FrmAddNeedlinesWithMapping!MappingID = mapId
End If
'Do Until MappingID <> mapId
'mapId = mapId + 1
.MoveNext
Loop

Now the only issue is getting that darn mapID to pass back to the MappingID. :confused:

Thanks for pointing out the lack of .movenext ;)
 
Last edited:

Adrianna

Registered User.
Local time
Today, 16:27
Joined
Oct 16, 2000
Messages
254
No Current Record?

Okay...couldn't pass the mappingID back and I don't know why, so I did an:
PHP:
                rst.AddNew
                rst.Fields("LocationID") = (LocationID)
                rst.Fields("URIC") = (URIC)
                rst.Fields("Justification") = (Justification)
                rst.Fields("ExternalOrganization") = (ExternalOrganization)
                rst.Fields("MappingID") = (mapId)
                rst.Fields("NodeType") = (NodeType)
                rst.Update
                rst.MoveLast

So, I think I'm okay for now!

THANKS!
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 16:27
Joined
Feb 19, 2002
Messages
43,550
You are using With rst but MappingID in the following statement isn't preceeded by a period.
Do While MappingID <> mapId

If you are not getting a compile error, it is because you haven't specified Option Explicit.
 

Users who are viewing this thread

Top Bottom