subform control correct syntax (1 Viewer)

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
I have a main form

frmTicket

and a subform on the above form named

frmTicketDetails

I am trying to setProperty in the subform on control FoodID

Please correct my mistakes none of these work

Form.frmTicket.frmTicketDetails.Form.FoodID

Form!frmTicket!frmTicketDetails.form.FoodID

Form.frmTicketDetails.FoodID
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:24
Joined
Aug 30, 2003
Messages
36,118
By the way, note they all start with "Forms", not "Form".
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:24
Joined
Oct 29, 2018
Messages
21,358
Hi. There's a small detail on the syntax that's easy to miss since, by default, we all get lucky in the way Access does things automatically. And that is, the name of the subform in the syntax "has to be" the name of the subform control/container on the main form and not the name of the form it contains (Source Object). Hope it makes sense...
 

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
I guess I do not know how to find the name of the control.

I am missing something important obviously.

When I look at the main form in design view I do not know where to find the name of the control.

Sorry to be so clueless.
 

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
Ok, I thanked you for clarifying the Source Object problem. I am using the right name.
 

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
Here is my latest try

Forms!frmTicket!frmTicketDetails.Form!FoodID

still wrong. I have looked at that web site in an earlier post many times and I just do not get it.

my subform name and source object are the same name.

Forms!Mainform!SourceObjectname.Form!ControlNameonsubform

What am I missing?????
 

Dreamweaver

Well-known member
Local time
Today, 16:24
Joined
Nov 28, 2005
Messages
2,466
Forms!mainformname!subformname!Controlonform


you have the subforms name and also the source object which is the name of the object as you see it in the nav panel so the name and source can be different always reference the name of any given subform

I wrote the 2 below into a main form to reference a subforms controls properties note there are a number of ways of doing this


Download my Employees example there are a few items that should help I have just uploaded a new version here: https://www.access-programmers.co.uk/forums/showpost.php?p=1623602&postcount=6


Code:
Me.frmEstimateProductsLineItems.Form.Controls("ProductID").ColumnWidths = "1.702cm;9cm;2cm;1.517cm"
         Me.frmEstimateProductsLineItems.Form.Controls("ProductID").TextAlign = 2
hope it helps
 
Last edited:

isladogs

MVP / VIP
Local time
Today, 16:24
Joined
Jan 14, 2017
Messages
18,186
The first line of the previous answer was incomplete - missing Form.
However the code sample showed that correctly.
As the previous post stated, there are several valid ways of doing this

Hopefully the following is correct
Forms!frmTicket.frmTicketDetails.Form.FoodID

Or if you are on the form frmTicket, use the Me.notation
Me.frmTicketDetails.Form.FoodID

I prefer the latter method to keep it as simple as possible
 

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
I tried the above and it did not work.

I have attached my DB I have messed something up.

I have 2 macros that work off of the buttons on the main form.

the Guest button puts Guest in the Customer name.

The Fries button should put Fries in the first record of the subform.

If I put the button on the subform it works fine.

Thank you for looking at it.
 

Attachments

  • CafePOS.accdb
    876 KB · Views: 113

theDBguy

I’m here to help
Staff member
Local time
Today, 09:24
Joined
Oct 29, 2018
Messages
21,358
I tried the above and it did not work.

I have attached my DB I have messed something up.

I have 2 macros that work off of the buttons on the main form.

the Guest button puts Guest in the Customer name.

The Fries button should put Fries in the first record of the subform.

If I put the button on the subform it works fine.

Thank you for looking at it.
Hi. Unfortunately, I don't have a lot of time to investigate at the moment, but I am thinking this could be a limitation of using a macro. If you tried using [Event Procedure] and then use the following VBA code, it works as you have described. That is, it changes the first record in the subform to Fries.
Code:
Private Sub Command26_Click()
Me.frmTicketDetails.Form!FoodID = 1

End Sub
 

tinher

Registered User.
Local time
Today, 09:24
Joined
May 11, 2019
Messages
30
Perfect! That works.

I just did not know how to code it without using a macro and it worked on the main form.

Thank You so much!!!!
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:24
Joined
Oct 29, 2018
Messages
21,358
Perfect! That works.

I just did not know how to code it without using a macro and it worked on the main form.

Thank You so much!!!!
Hi. When I have more time, I'll see if I can make the macro work. But at least you can move on for now. Good luck with your project.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:24
Joined
Oct 29, 2018
Messages
21,358
Hi. I finally got a chance to play with it some more and was able to find a way to make the following syntax work in a macro.
Code:
[Forms]![frmTicket].[frmTicketDetails].[Form]![FoodID]
However, there is a catch. In order to make it work in a macro, I had to use the SetValue action rather than the SetProperty action. Please see the attached updated copy of your database. Hope this helps...
 

Attachments

  • CafePOS.zip
    36.6 KB · Views: 115

Users who are viewing this thread

Top Bottom