Solved

How update field in a table based on seletion in combobox

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

785 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