Update record in subform

tinher

Registered User.
Local time
Today, 06:30
Joined
May 11, 2019
Messages
30
I am using buttons to add data. I used this code. It works perfectly on the main form.

Code:
    If Me.NewRecord = False Then
        DoCmd.GoToRecord acDataForm, "frmTicket", acNewRec
        Me.CustomerID = 1

    End If

I need to add another button on the main form that adds data to the subform. I know Me. is used on main form. I cannot get the syntax right for the subform.

Main form is frmTicket
subform is frmTicketDetailsSubform

Field I want to update is
FoodID so if it was on the main form it would be Me.FoodID = 1

I tried this before I knew Me. did not work on subform

Code:
    If Me.NewRecord = False Then
        DoCmd.GoToRecord acDataForm, "frmTicketDetailsSubform", acNewRec
        Me.FoodID = 1

    End If

Thank You for the help
 
Last edited by a moderator:
Why do you need code? Master/Child Links properties should automatically associate records and save ID.

Why would CustomerID or FoodID always be 1?
 
I have clicked on that link to the examples and I cannot find what I need. I tried and failed.

I provided the form names I was hopping someone would update my code with the correct syntax.
 
I have a button with this code attached to the on click event.

Like I said it works on the frmTicket main form. I have added another button to the main form that I want to put a 1 in the FoodID field of the subform.

It is not always 1. Just when I push the button I added to make it 1.

Thanks.
 
Reference to subform/subreport must be through the container control that holds the form/report. I always name container different from the object it holds, such as ctrDetails. So, example:

Me.ctrDetails!FoodID = 1

I also name controls different from field names, such as tbxFood:

Me.ctrDetails.Form.tbxFood = 1
 
Reference to subform/subreport must be through the container control that holds the form/report. I always name container different from the object it holds, such as ctrDetails. So, example:

Me.ctrDetails!FoodID = 1

I also name controls different from field names, such as tbxFood:

Me.ctrDetails.Form.tbxFood = 1


This makes no sense to me. Sorry.
 
My main form is

frmTicket

My subform on frmTicket is

frmTicketDetailsSubform

my subform has a field named FoodID
I want to put a 1 in that field when I click the button
 
I found the original code in this thread

Command button to input data in a table

John Big Booty gave the good info
 
When you preface a field with "Me.", that means you are referring to a control on the same form that your code is executing on.
 
No link provided in post 10.

I gave you example using some object names I use because I don't know your db. The syntax still applies.

A subform/subreport is created by installing a subform/subreport container control on form or report. That container has SourceObject property that can reference a table/query/form/report. To reference the form (and therefore its controls) within the container, must reference the container. So with that in mind, read my previous post again.
 

Users who are viewing this thread

Back
Top Bottom