Results 1 to 9 of 9
  1. #1
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40

    Update not overwrite

    Can you please give me the code on which i can just update an existing entry in a table?
    Suppose I have a table that has field names, field1, field2, field3.. field1 and field2 has already a value and field3 = Null (im talking about the value in the database)
    what i want to happen is to have a form to be filled up to update a value in field3 without affecting field1 and field2.. I hope i made it clear.. thanks in advance!

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Basically what you want to do is update the records in your database this can be done using Update query

    E.g. I want to update Field3 in tbl1 then: This example will set the Value of Field1 to Yes for all the records in the table.

    Dim strSQL as string

    strSQL="Update tbl1 Set Filed1='Yes';"

    When I want the update to be Specific Like update Field1 to Yes where Field2=No
    strSQL="Update tbl1 Set Field1='Yes' Where Field2='No';"


    No you have to Run the SQL to complete the update. This can be done either by

    Docmd.RunSQL StrSQL
    or
    Currentdb.Execute strSQL,dbFailOnError


    So the complete code would look like: (I have used the second Example please choose the strSQL according to your Requirement)

    Dim strSQL as String
    strSQL="Update tbl1 Set Field1='Yes' Where Field2='No';"
    Currentdb.Execute strSQL,dbFailOnError

  3. #3
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40
    oh.. i'll try the code first.. thanks for the reply btw! you rock!

  4. #4
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40
    I tried your code and i got error.. "Too few parameters, expected 3" here's my code..

    Dim strSQL2 As String
    strSQL2 = "Update Transaction SET TimeOut = Me.cTime Where Barcode=TxtCode AND EntryDate=Me.ccDate;"
    CurrentDb.Execute strSQL2

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Updating specific entries an example that u can relate to:

    Dim strSQL as String
    strSQL="Update tblEmployee Set Contractor='1' Where EmployeeType='1';"
    Currentdb.Execute strSQL, dbFailOnError

  6. #6
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40
    sir maximus, i have followed it already, and i got errors.. here's the code again.. please help..

    Dim strSQL2 As String
    strSQL2 = "Update Transaction SET TimeOut = Me.cTime Where Barcode=TxtCode AND EntryDate=Me.ccDate;"
    CurrentDb.Execute strSQL2

  7. #7
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Try this:
    Time and date Fields have to be enclosed with #
    Text Fields with '
    Notice How I have use the Form Control Values in the String with & Me.cTime

    Dim strSQL2 As String
    strSQL2 = "Update Transaction SET TimeOut = #" & Me.cTime & "# Where Barcode='" & TxtCode & "' AND EntryDate=#" & Me.ccDate & "#;"
    CurrentDb.Execute strSQL2,dbFailOnError

  8. #8
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    is the problem solved if ues mark this thread solved.

  9. #9
    dada is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    40
    thanks! you nailed it again! your so awesome!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Overwrite existing tables
    By magua in forum Import/Export Data
    Replies: 1
    Last Post: 06-21-2010, 11:32 AM
  2. XML File Import To Access...Overwrite Issue
    By wipers123 in forum Import/Export Data
    Replies: 0
    Last Post: 02-11-2010, 12:27 PM
  3. Table Overwrite
    By ml2009 in forum Access
    Replies: 3
    Last Post: 01-14-2010, 07:06 AM
  4. Update Query- selective update?
    By stephenaa5 in forum Queries
    Replies: 1
    Last Post: 10-29-2009, 11:15 AM
  5. Import and overwrite?
    By Ben in forum Import/Export Data
    Replies: 3
    Last Post: 08-11-2009, 08:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums