Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Update records through a subform

Posted on 2016-11-04
5
Medium Priority
?
29 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 52

Accepted Solution

by:
Gustav Brock earned 2000 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 52

Assisted Solution

by:Gustav Brock
Gustav Brock earned 2000 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 52

Expert Comment

by:Gustav Brock
ID: 41898879
Solved.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

971 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