Solved

How update field in a table based on seletion in combobox

Posted on 2013-06-12
2
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

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…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

739 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