Solved

How update field in a table based on seletion in combobox

Posted on 2013-06-12
2
427 Views
Last Modified: 2013-06-13
I have this afterupdate event on a checkbox on a form.  It is an unbound form.

Private Sub chkbxReturned_AfterUpdate()
    Dim RS As DAO.Recordset
    Set RS = CurrentDb.OpenRecordset("tblImportRecords")
        RS.Edit
        RS!Returned = Me.chkboxReturned
        RS.Update
    End If
End Sub

But I don't know how to get code in here to tell it which record to update.  The selected record is in the combobox named cboReturned and the key field is ID in the table tblImportRecords.
0
Comment
Question by:SteveL13
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
Private Sub chkbxReturned_AfterUpdate()

currentdb.execute "Update  tblImportRecords set Returned = " & Me.chkboxReturned & " Where ID=" & me.cboReturned , dbfailonerror


End sub

or this

Private Sub chkbxReturned_AfterUpdate()
    Dim RS As DAO.Recordset
    Set RS = CurrentDb.OpenRecordset("Select * from tblImportRecords Where ID=" & me.cboReturned)

if RS.EOF then exit sub

        RS.Edit
        RS!Returned = Me.chkboxReturned
        RS.Update
    End If
RS.Close
End Sub
0
 
LVL 4

Expert Comment

by:BAKADY
Comment Utility
Private Sub chkbxReturned_AfterUpdate()
    CurrentDb.Execute "UPDATE tblImportRecords SET Returned = " & Me.chkboxReturned & " WHERE ID = " & Me.cboReturned & ""
End Sub

Open in new window

if your db-field is a string type, to pass the value into the field without errors use something like this (quoted):
 CurrentDb.Execute "UPDATE tblImportRecords SET yourField = '" & replace(yourStringValue, "'", "''") & "' WHERE ID = " & Me.cboReturned & ""

Open in new window

0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now