Solved

Update records through a subform

Posted on 2016-11-04
5
21 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
  • 3
  • 2
5 Comments
 
LVL 49

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 49

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 49

Expert Comment

by:Gustav Brock
ID: 41898879
Solved.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now