Solved

How update field in a table based on seletion in combobox

Posted on 2013-06-12
2
466 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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39242341
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
ID: 39242362
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
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…

740 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