Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Location
    NM, USA
    Posts
    97

    Question Unanswered: Trouble editing records

    In the forms I use in my database to ENTER information and create new records, there's no problem there. But I have a form that I used the form WIZARD (ugh ugh ugh) to design (I've attached an image of it in design mode).

    There are two fields in the table this form is bound to that are updated whenever a record is changed, "Modified" (the time and date) and "User" (the user that has performed the modification)

    The problem I have is using the recordset object and working with the design of this form. I had some code that I THOUGHT should have worked (and it did KIND of work)... but no matter which record on the form I'd edit, it would always just edit the first record. It must not have saved though, because I can't find it, and I can't remember what I wrote.

    : \ I don't know what to do.


    Maybe this'll help...
    Code:
    Private Sub intEmpID_AfterUpdate()
        
    Dim db As Database Dim rst As Recordset Set db = CurrentDb Set rst = db.OpenRecordset("tblContractors") rst.Bookmark = rst.LastModified rst.Edit rst.Fields("Modified") = Now rst.Fields("User") = Log1.GUsername rst.Update
    End Sub
    The POINT is if any field of a record shown in the form is edited, the "Modified" and "User" columns of the record need to be updated with Now() and the current username.

    Maybe that's a little more specific.
    Attached Thumbnails Attached Thumbnails ss1.bmp  
    Last edited by atsukoarai86; 01-26-09 at 12:29.
    "Unix is user friendly... It's just very picky about its friends."

    The best things in life...are well-documented.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    well if you don't know what code you used, and the description of what you are trying to do is pretty vague, how are we supposed to be able to help you?
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Sep 2008
    Location
    NM, USA
    Posts
    97

    Thumbs down

    Quote Originally Posted by healdem
    well if you don't know what code you used, and the description of what you are trying to do is pretty vague, how are we supposed to be able to help you?
    Well, I described it as best I could. If you wanted to help, maybe you could have asked a specific question instead of just wasting space. k thx.
    "Unix is user friendly... It's just very picky about its friends."

    The best things in life...are well-documented.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    first off id make it expelicit which type of recordset you are using, whether its ADO/ADODB or DAO

    if it used to work and now doesn't then its possible that the new installation is trying to use ADO, and old code may well be DAO.

    have you proved that the code is reaching the section that does the update
    ie put a watch/breakpoint on the section

    if it were me I'd probbaly set those values as part of the forms before update code rahter than create the additional overhead int he after update.

    If I must put the code in the after update then I'd probably use a docmd.runsql (or is it docmd.exec)?
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    I agree with healdem! Since this is a bound form, going to all this trouble to update two bound fields seems like overkill! In the Form_BeforeUpdate, simply assign the values, something like
    Code:
    Private Sub Form_BeforeUpdate(Cancel As Integer)
      Me.Modified = Now
      Me.User = Log1.GUsername
    End Sub
    although I'm not exactly sure what Log1.GUsername is.
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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