Go Back   Access World Forums > Microsoft Access Discussion > Macros

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 05-18-2019, 04:19 PM   #1
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
subform control correct syntax

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

tinher is offline   Reply With Quote
Old 05-18-2019, 04:26 PM   #2
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,870
Thanks: 12
Thanked 4,029 Times in 3,966 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: subform control correct syntax

Here's a good reference on syntax:

http://www.theaccessweb.com/forms/frm0031.htm
__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is online now   Reply With Quote
Old 05-18-2019, 04:27 PM   #3
pbaldy
Wino Moderator
 
pbaldy's Avatar
 
Join Date: Aug 2003
Location: Nevada, USA
Posts: 32,870
Thanks: 12
Thanked 4,029 Times in 3,966 Posts
pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold pbaldy is a splendid one to behold
Re: subform control correct syntax

By the way, note they all start with "Forms", not "Form".

__________________
Paul
Microsoft Access MVP 2007-2019

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
pbaldy is online now   Reply With Quote
The Following User Says Thank You to pbaldy For This Useful Post:
tinher (05-19-2019)
Old 05-18-2019, 04:48 PM   #4
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,024
Thanks: 35
Thanked 720 Times in 703 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: subform control correct syntax

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...
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
tinher (05-19-2019)
Old 05-19-2019, 05:41 AM   #5
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
Re: subform control correct syntax

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 is offline   Reply With Quote
Old 05-19-2019, 05:47 AM   #6
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
Re: subform control correct syntax

Ok, I thanked you for clarifying the Source Object problem. I am using the right name.
tinher is offline   Reply With Quote
Old 05-19-2019, 05:58 AM   #7
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
Re: subform control correct syntax

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!ControlNameon subform

What am I missing?????

tinher is offline   Reply With Quote
Old 05-19-2019, 06:02 AM   #8
MickJav
Newly Registered User
 
Join Date: Nov 2005
Location: Margate
Posts: 777
Thanks: 39
Thanked 31 Times in 26 Posts
MickJav is on a distinguished road
Re: subform control correct syntax

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...02&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
__________________
DD's Simple Home Accounts:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

DD's Book Library:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Under Development DD's Works Manager Due end August 2019, DD's Employee Works Rota Demo Expected 2020

Last edited by MickJav; 05-19-2019 at 06:13 AM.
MickJav is offline   Reply With Quote
Old 05-19-2019, 06:19 AM   #9
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 9,427
Thanks: 106
Thanked 2,529 Times in 2,322 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: subform control correct syntax

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
__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 05-19-2019, 06:31 AM   #10
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
Re: subform control correct syntax

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.
Attached Files
File Type: accdb CafePOS.accdb (876.0 KB, 6 views)
tinher is offline   Reply With Quote
Old 05-19-2019, 07:42 AM   #11
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,024
Thanks: 35
Thanked 720 Times in 703 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: subform control correct syntax

Quote:
Originally Posted by tinher View Post
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
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
The Following User Says Thank You to theDBguy For This Useful Post:
tinher (05-19-2019)
Old 05-19-2019, 07:58 AM   #12
tinher
Newly Registered User
 
Join Date: May 2019
Posts: 24
Thanks: 5
Thanked 0 Times in 0 Posts
tinher is on a distinguished road
Re: subform control correct syntax

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!!!!
tinher is offline   Reply With Quote
Old 05-19-2019, 08:29 AM   #13
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,024
Thanks: 35
Thanked 720 Times in 703 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: subform control correct syntax

Quote:
Originally Posted by tinher View Post
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.
__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Old 05-19-2019, 11:50 AM   #14
theDBguy
Iím here to help
 
theDBguy's Avatar
 
Join Date: Oct 2018
Location: SunnySandyEggo
Posts: 3,024
Thanks: 35
Thanked 720 Times in 703 Posts
theDBguy will become famous soon enough theDBguy will become famous soon enough
Re: subform control correct syntax

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...
Attached Files
File Type: zip CafePOS.zip (36.6 KB, 5 views)

__________________
Just my 2 cents...

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
theDBguy is online now   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Correct VBA syntax for a form field inside a tab control JamesWB Forms 6 08-08-2014 08:23 AM
correct syntax to refer to a control on a nested subform in Access 2013 jd9913 Forms 5 03-23-2014 07:11 AM
syntax issue: dynamic reference to a subform control paiopaio Modules & VBA 10 07-07-2011 12:11 AM
Control on a Subform (Syntax) xolo Modules & VBA 3 12-28-2009 10:33 AM
need correct control source syntax connieharper Reports 0 06-27-2001 09:34 AM




All times are GMT -8. The time now is 08:22 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World