User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS Access and FileMaker Pro section within the Web Development category of DaniWeb, a massive community of 426,920 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,359 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS Access and FileMaker Pro advertiser: Programming Forums
Views: 5196 | Replies: 2
Reply
Join Date: Aug 2006
Posts: 22
Reputation: stealthdevil is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
stealthdevil stealthdevil is offline Offline
Newbie Poster

Do Loop

  #1  
Oct 4th, 2006
Hi,
I'm trying to use a Do Loop to look at 2 seperate tables. It needs to check the value in one field on the first table. If it finds a "T" it should look to a field in the other table and count down 3 rows. Then it needs to put the values from those 3 rows into a field beside the field that contains the "T". LOOP
Then it goes to the next row "below the "T"". If its another "T" then it goes to the other table and counts down 3 rows from where it left off last time. Then puts those 3 values below the last ones.

T = 3
D = 2
S = 1

There are actually 2 fields that get copied from the second table.
What property could I use for this? I thought maybe the Count property, but I don't think it actually get the value.

Thanks for any help.
-Dave
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2006
Posts: 22
Reputation: stealthdevil is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
stealthdevil stealthdevil is offline Offline
Newbie Poster

Re: Do Loop

  #2  
Oct 5th, 2006
This is my code so far. I keep getting an "object variable not defined" error. I''m not sure why I'm getting this.

Option Compare Database
Option Explicit

Function setlocations()
DoCmd.SetWarnings False
'declare necessary variables
Dim db As Database
'Dim rsRev As New ADODB.Recordset
Dim rsRev As Recordset
Dim rsLoc As Recordset
Dim sLoc As String
Dim iLevel As Integer
Dim sBreak As String
'point to database and tables
Set db = CurrentDb()
Set rsLoc = db.OpenRecordset("select *" & "from tbl_loc")
Set rsRev = db.OpenRecordset("select *" & "from tbl_os_reverse")
'Loop through records
rsRev.MoveFirst
'Do Until rsRev.Fields("[BREAKPT]").Value = " "
'Do While rsRev.EOF = False
Do While Not rsRev.EOF
sBreak = rsRev.Fields("[BREAKPT]").Value
sLoc = rsLoc.Fields("[LOCATION]").Value
iLevel = rsLoc.Fields("[LEVELS]").Value
rsRev.Edit
rsRev.Fields("[LOC SEQ]").Value = iLevel
rsRev![LOCATION] = sLoc
rsRev.Update
rsRev.MoveNext
If sBreak = "T" Then
rsLoc.Move 3
ElseIf sBreak = "D" Then
rsLoc.Move 2
Else
rsLoc.MoveNext
End If
'reclaim memory that recordset was using
Set rsLoc = Nothing
Set rsRev = Nothing
Loop

rsRev.Close
rsLoc.Close
End Function
Reply With Quote  
Join Date: Aug 2006
Posts: 22
Reputation: stealthdevil is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
stealthdevil stealthdevil is offline Offline
Newbie Poster

Re: Do Loop

  #3  
Oct 6th, 2006
Well, I got the error fixed. Now I just have to figure out how to end the rsLoc table if it runs out of records before the rsRev table.


 
Option Compare Database
Option Explicit

Function setlocations()
DoCmd.SetWarnings False
'declare necessary variables
Dim db As Database
Dim rsRev As Recordset
Dim rsLoc As Recordset
Dim sLoc As String
Dim iLevel As Integer
Dim sBreak As String
Dim sPar As String

'point to database and tables
Set db = CurrentDb()
Set rsLoc = db.OpenRecordset("tbl_loc", DB_OPEN_TABLE)
Set rsRev = db.OpenRecordset("tbl_os_reverse", DB_OPEN_TABLE)
'Loop through records
rsRev.MoveFirst
While Not rsRev.EOF
   
    sBreak = rsRev.Fields("[BREAKPT]").Value
    sLoc = rsLoc.Fields("[LOCATION]").Value
    iLevel = rsLoc.Fields("[LEVELS]").Value
    rsRev.Edit
    rsRev.Fields("[LOC SEQ]").Value = iLevel
    rsRev![LOCATION] = sLoc
    rsRev.Update
    rsRev.MoveNext
    If rsLoc.EOF Then
    If sBreak = "T" Then
        rsLoc.Move 3
    ElseIf sBreak = "D" Then
        rsLoc.Move 2
    Else
        rsLoc.MoveNext
    End If
Wend

rsRev.Close
rsLoc.Close
End Function
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MS Access and FileMaker Pro Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the MS Access and FileMaker Pro Forum

All times are GMT -4. The time now is 11:44 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC