?
Solved

How update field in a table based on seletion in combobox

Posted on 2013-06-12
2
Medium Priority
?
475 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Suggested Courses

752 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