Weird error in form (1 Viewer)

CedarTree

Registered User.
Local time
Today, 16:10
Joined
Mar 2, 2018
Messages
404
Hello - I have a subform that has a field called FileID. When a certain event is triggered, I want to set a text box on the main form = FileID. I'm using the simple code below. The text box has no events, etc. so I can't imagine there's a recursive thing going on. But I keep getting a "too complicated expression" error. Help please?!? THANKS!

Code:
Forms("usysfrmMain").Controls("zFileID").Value = iFileID
'I've also tried this:
Forms("usysfrmMain").zFileID.Value = iFileID
 

June7

AWF VIP
Local time
Today, 12:10
Joined
Mar 9, 2014
Messages
5,473
This is backwards. Subform normally does not dictate main form data. Do this form and subform have a relationship (are Master/Child Links properties set)?

Is zFileID textbox UNBOUND? Is iFileID a VBA variable?

What event is triggered? If it is behind subform your examples should work. Here is another version: Me.Parent.zFileID = iFileID

Could provide db for analysis.
 
Last edited:

Edgar_

Active member
Local time
Today, 15:10
Joined
Jul 8, 2023
Messages
430
You have not defined iFileID (besides, you said it was FileID, not iFileID). You have not mentioned if this code is in a module or a form. There is extra stuff going on if you're getting that error. So it's best that you tell us more. I don't see a reference to any subform control there.

Generally, if you have a subform with a field called FileID and you want to make a textbox on the main form have the value of that field, you'd do something like this:
If in a module.
Forms("MainForm").Form.Controls("MainFormTextbox").Value = MainForm.Form.SubformControlName.Form.Controls("ControlName").Value

From main form:
Me.MainFormTextbox.Value = Me.SubformControlName.Form.Controls("ControlName").Value

From subform:
Me.Parent.Form.Controls("MainFormTextbox").Value = Me.ControlName.Value

There are many different variations for this. A LOT. You better give us some names AND your scenario.
 
Last edited:

CedarTree

Registered User.
Local time
Today, 16:10
Joined
Mar 2, 2018
Messages
404
Thanks - yes, I know this is not typical. But I don't want zFileID on the mainform to always be equal to FileID on the subform for specific project reasons. I define iFileID as a long type and set it equal to FileID on the subform. I will try your syntax just above Edgar and report back. Thanks.

EDIT/UPDATE - still no luck. In fact, 90% of the time it crashes Access. To provide more detail:
Main form has a data field called zFileID
Subform has a data field called FileID. I define iFileID as long = subform.FileID
When I walk through the coding step by step, iFileID is a long # (not null or anything). I'm just from the subform trying to set the value of zFileID. Maybe I should call an external sub in a module to set the value?
 
Last edited:

June7

AWF VIP
Local time
Today, 12:10
Joined
Mar 9, 2014
Messages
5,473
Me.Parent does not require .Form reference but works as well. I tested both.
 

CedarTree

Registered User.
Local time
Today, 16:10
Joined
Mar 2, 2018
Messages
404
Strange but me.parent works! The other syntax did not. But I'll take it. Thanks!
 

Edgar_

Active member
Local time
Today, 15:10
Joined
Jul 8, 2023
Messages
430
Me.Parent does not require .Form reference but works as well. I tested both.
Yeah, too many variations to choose from, we could use the scary explicit version too where there are no shortcuts/defaults, but at least this time, OP says it's solved.
 

June7

AWF VIP
Local time
Today, 12:10
Joined
Mar 9, 2014
Messages
5,473
I always name controls different from field names to remove any possibility of ambiguity in code references.

Are you setting value of field or an UNBOUND textbox?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 15:10
Joined
Feb 28, 2001
Messages
27,188
I'm going to toss in an "aside" comment.

In the following reference:

Code:
Forms("usysfrmMain").Controls("zFileID").Value = iFileID

Use of .Value is superfluous. For any control that HAS a value, the default property is .Value so can be omitted from the reference. Less typing.
 

Users who are viewing this thread

Top Bottom