|
-
Jan 19th, 2000, 10:47 PM
#1
Thread Starter
Hyperactive Member
I'm a database newby and I need a little help
I have an access database with the following fields:
ID, ParentID, Level
Level and ParentID are filled with numbers Level is filled with zero's.
I want to have a loop that looks at every record an checks if the ID of that record matches a ParentID in any of te other records if this is the case the Level field of that record should be set to 1
Can anybody help me with this please ?
-
Jan 19th, 2000, 11:42 PM
#2
Thread Starter
Hyperactive Member
Did som studying :-)
Here's my solution in case you would hate me for not sharing...
Code:
Dim db As Database
Dim rs As Recordset
Dim rs2 As Recordset
Dim iValue As Integer
Dim iCounter As Integer
'open database
Set db = DBEngine.OpenDatabase(App.Path & "\4_new.mdb")
'open recordset using SQL
Set rs = db.OpenRecordset("Select * from Menu")
Set rs2 = db.OpenRecordset("Select * from Menu")
i = 1
Do Until rs.EOF = True
i = i + 1
'rs.Fields("Name").Valu
iValue = rs.Fields("ID").Value
Do Until rs2.EOF = True
If rs2.Fields("ParentID").Value = iValue Then
rs.Edit
rs.Fields("submenu").Value = 1
rs.Update
End If
rs2.MoveNext
DoEvents
Loop
rs2.MoveFirst
rs.MoveNext
Label1.Caption = i
DoEvents
Loop
'close db/rs
rs.Close
rs2.Close
db.Close
Set rs = Nothing
Set db = Nothing
Label1.Caption = "Done..."
[This message has been edited by Inhumanoid (edited 01-20-2000).]
-
Jan 21st, 2000, 11:43 PM
#3
New Member
Why all the hard coding stuff?
Execute this SQL query:
"UPDATE Menu INNER JOIN Menu AS Menu_1 ON Menu.ID = Menu_1.ParentID SET Menu.[Level] = 1;"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|