Results 1 to 2 of 2

Thread: problem understaing this vba code!

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Arrow 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

  2. #2
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    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.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width