Solved

Update records through a subform

Posted on 2016-11-04
5
25 Views
Last Modified: 2016-11-23
I have a subform whose record source is a table (MyTable). The subform’s data is displayed as continuous forms.

In the detail section of the subform I have a command button. To the right of the button are textboxes which are used to display values from the various fields in MyTable.

So, when the subform is in Form View, the records from MyTable are displayed (one row for each record) and there is a command button next to each record

What I’m trying to accomplish is to run an update query that will update MyTable but only update the record next to the particular command button I click.  Right now, it seems to be updating ALL records in MyTable.  

The update I’m trying to perform is to just set at YES/NO field (Field1) from No to Yes but only for the selected record.
Here is the update query as it is now (that is affecting the entire table, not just the target record):

UPDATE MyTable SET Field1 = -1;

I also tried this but it doesn't seem to be working either (ID is the primary key):

UPDATE MyTable SET Field1 = -1
WHERE MyTable.ID=Forms!Form1!Subform1!txt_ID;
0
Comment
Question by:dbfromnewjersey
[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
  • 3
  • 2
5 Comments
 
LVL 50

Accepted Solution

by:
Gustav Brock earned 500 total points (awarded by participants)
ID: 41874773
You are making it way too hard for yourself.

Just update the form from the click event of the button:

    Me!YourField.Value = True

No query, no updating, done.

/gustav
0
 

Author Comment

by:dbfromnewjersey
ID: 41874808
Thanks but that's now producing a 'Return Without GoSub' error message.

Here is the code under the subform's command button on click event:

Private Sub cmd_Select_Click()
On Error GoTo Err_cmd_Select_Click

'DoCmd.OpenQuery "qry_Append_Temporary_Table" <---- used to populate a different subform. Tried  commenting out to get rid of the error but no success.

Me!Transaction_Entered_Marker.Value = True

Me.Parent.frm_Subform2.Form.Requery

Exit_cmd_Select_Click:
    Exit Sub

Err_cmd_Select_Click:
    MsgBox Err.Description
    Resume Exit_cmd_Select_Click
   
End Sub
0
 

Author Comment

by:dbfromnewjersey
ID: 41874852
I must be doing something wrong because that method doesn't update the selected record.

As an example, I have 2 records in my table. Therefore, the subform displays 2 records with a command button next to each. If I click the command button next to the first record, nothing happens.  If I click the second record, the table does get updated.
0
 
LVL 50

Assisted Solution

by:Gustav Brock
Gustav Brock earned 500 total points (awarded by participants)
ID: 41874863
No query, no updating, done.

Private Sub cmd_Select_Click()

    Me!Transaction_Entered_Marker.Value = True

    ' And if you wish the record saved at once:
    Me.Dirty = False

End Sub 

Open in new window

/gustav
0
 
LVL 50

Expert Comment

by:Gustav Brock
ID: 41898879
Solved.
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

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…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

734 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