CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2001
    Posts
    13

    Problem! Why can't I update JUST 1 RECORD??

    Hello again everyone. I got the help I needed last time, but now another problem has popped up. I am using the following code to update the "last person to update" field. For some reason, it takes the current user's name (database is MS Access 2002), and puts the user's name is EVERY record in the field. Is there a way to specify to ONLY put the name in the record that is currently on the screen in Access? Maybe passing the variable from Access somehow, and searching, or something? Or am I not going to be able to do this?

    CODE:

    Private Sub SAVE_RECORD_Click()

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Dim colItems As Items
    Dim tblContacts As Recordset
    Dim upContactId As UserProperty
    Dim strMessage As String
    Dim strTableName As String



    Set db = OpenDatabase("c:\sulphur db\sulphur2002.mdb")

    'Open the table.
    Set tblContacts = db.OpenRecordset("Contacts", dbOpenDynaset)

    sSQL = "update Contacts set Last_Person = '" & CurrentUser() & "'"
    db.Execute sSQL


    End Sub
    Thanks!

    Bill Garrett


  2. #2
    Join Date
    Jul 1999
    Posts
    84

    Re: Problem! Why can't I update JUST 1 RECORD??

    Hello,
    Attach the where condition, at the end of the sql statement like where [columnname]=[value of the record in that column]

    If u use the above condition it will update the record that is shown one the screen, provided the where condition returns only the record that is shown on the screen.

    Please rate if the solution is helpful

    Thanks
    Harini

  3. #3
    Join Date
    Aug 2001
    Location
    New York, USA
    Posts
    169

    Re: Problem! Why can't I update JUST 1 RECORD??



    private Sub SAVE_RECORD_Click()

    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

    Dim colItems as Items
    Dim tblContacts as Recordset
    Dim upContactId as UserProperty
    Dim strMessage as string
    Dim strTableName as string



    set db = OpenDatabase("c:\sulphur db\sulphur2002.mdb")

    'Open the table.
    set tblContacts = db.OpenRecordset("Contacts", dbOpenDynaset)

    'make sure sSQL is empty
    sSQL = ""
    'add sql statement to sSQL
    sSQL = sSQL & "UPDATE Contacts "
    sSQL = sSQL & "set Last_Person = " & "'" & CurrentUser() & "' "
    sSQL = sSQL & "WHERE fieldname = & "'" & value/variable & "'"

    db.Execute sSQL

    End Sub




    [email protected]

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

Featured