problem understaing this vba code!
Hi all. I got a access vba 2000 code that i hardly understand what some of its part doing.
i need to learn this since i want to learn how to refrence these system tables.
I be happy if some expert explain to me what these part does.Thanks
part1:
Code:
Set rsMetadb = MetaDB.OpenRecordset("SysKeys")
part2:
Code:
For Each idx In tbl.Indexes
bUpdate = False
rsMetadb.AddNew
rsMetadb("Tablename") = tbl.Name
If idx.Primary = True Or idx.Unique = True Then rsMetadb("Keyname") = idx.Name
part3:
Code:
If bUpdate Then rsMetadb.Update
part4:
Code:
rsMetadb("Keytype") = "PRIMARY"
complete code:
Code:
Dim bUpdate, ref As String
Dim i As Integer
Set rsMetadb = MetaDB.OpenRecordset("SysKeys")
For Each tbl In db.TableDefs
If Left(tbl.Name, 4) <> "MSys" Then
For Each idx In tbl.Indexes
bUpdate = False
rsMetadb.AddNew
rsMetadb("Tablename") = tbl.Name
If idx.Primary = True Or idx.Unique = True Then rsMetadb("Keyname") = idx.Name
'Check primary key
If idx.Primary = True Then
rsMetadb("Keytype") = "PRIMARY"
bUpdate = True
Else
'Check Alternate key
If idx.Unique = True And idx.Primary = False And idx.Foreign = False Then
rsMetadb("Keytype") = "ALTERNATIVE"
bUpdate = True
End If
End If
If bUpdate Then rsMetadb.Update
Next idx
End If
Next tbl
rsMetadb.Close
Re: problem understaing this vba code!
From what I understand in this code is that you are opening a recordset called "SysKeys" then scanning through all of the tables and appending either the primary key or each alternative key to the "SysKeys" table..
Some of this code suggests further declarations are somewhere in your code and you are also using DAO, there is also a boolean variable decalred as variant..
Part one open up the table "SysKeys" in a recordset
Part Two Loop around the keys in the table, this is the primary key
Part Three doesn't update the recordset until bUpdate is True
Part Four Setting the field "KeyType" to be primary.