Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Updating a Table in Code (Access 2K, O2KPro)

    OK, I've got a nice little function that generates a random password and now I want to open a table and step thru the records and write the passwords as they spring forth from my function during the iteration thru the table.

    A bit confused on how to get this to work and, as usual, most of the help information that I'd like to use simply doesn't want to display (or doesn't exist).

    I'm sure I'm just not getting the syntax right. -- well, hopefully that's the only problem.

    here's the psuedocode:

    Function GeneratePassword()
    <password code>
    var PassWord is loaded
    End Function

    Sub WritePassword()

    Dim dbs As DAO.Database
    Dim rst As DAO.Recordset

    Set dbs = CurrentDb
    Set rst = dbs.OpenRecordset("pwd")

    Do While Not rst.EOF
    Password = GeneratePassword
    rst![pwd] = Password
    rst.MoveNext
    Loop

    End Sub

    I keep getting this error message about CancelUpdate without AddNew or Edit, which leads me to think I've got the table opened in ViewOnly or something. Of course, I'm using DAO (why? not sure -- I got it to work in other code when trying to manipulate a table) and Access Help can't be bothered to help me. I'm pretty sure I've got something wrong with the code for getting the value generated by the function, but one step at a time...

    None of this code is all that dear to me, but I'd like to wrap the logic for generating the password string in a function since that feels really good. The thing is, how to step thru an existing table and assign the value the function creates in a specific column for each row of the table? I could do this easily enough in ASP but would rather do it in a VBS module.

    TIA!

    <img src=/S/compute.gif border=0 alt=compute width=40 height=20>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Updating a Table in Code (Access 2K, O2KPro)

    No, it means that you are trying to edit the recordset without issuing a rst.Edit and trying to edit it without an rst.Update to write the value.
    Charlotte

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Updating a Table in Code (Access 2K, O2KPro)

    thanks. your pithy response gave me what I needed to get the code to work. I ended up pasting the password generator code in the sub but that's no big deal..

    It worketh!

    Thanks again for your help.
    <img src=/S/bravo.gif border=0 alt=bravo width=16 height=30>

Posting Permissions

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