getting error on my form on one database but not the other which is the same (1 Viewer)

rainbows

Registered User.
Local time
Today, 12:19
Joined
Apr 21, 2017
Messages
425
i have created a unbound text box called (text 12) for linking 2 forms via the stock number yet it is showing an error see below screen shot the screen shot below shows the formular
yet on another copy of that same database it works. so i am now worried that there is a problem with how i have done it but i have used this type of method to do this on other forms

is there and better method of doing this ?
thanks steve




1667287757828.png

1667288058309.png




1667288139416.png

1667288538679.png
 

ebs17

Well-known member
Local time
Today, 21:19
Joined
Feb 7, 2020
Messages
1,946
Stocknumber is in both tables (main and subform). Therefore, it would certainly be easier to create a link directly via these two data fields.

Properties SubForm.LinkMasterFields, SubForm.LinkChildFields
 

rainbows

Registered User.
Local time
Today, 12:19
Joined
Apr 21, 2017
Messages
425
i am not sure how to do that if they are both subforms in an empty main form ?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 20:19
Joined
Feb 19, 2013
Messages
16,616
given your propensity to use meaningless names for your controls, perhaps you need to use the control name?
 

rainbows

Registered User.
Local time
Today, 12:19
Joined
Apr 21, 2017
Messages
425
1667303068990.png


i am confused. yes i know it is a meaningless name and must try and get better at this but have i not used the correct name in the field control?
=[Child68]![Form]![Stock Number]
thanks

steve
 

Gasman

Enthusiastic Amateur
Local time
Today, 20:19
Joined
Sep 21, 2011
Messages
14,310
View attachment 104273

i am confused. yes i know it is a meaningless name and must try and get better at this but have i not used the correct name in the field control?
=[Child68]![Form]![Stock Number]
thanks

steve
Who can tell?
Is child68 the name of the subform control?
Where eaxctly is that control located, which form/subform, where in the heirarchy of the forms?
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
I find it easier if you are linking text box Text12, to make it unbound
Then in the first forms on current Event
me.parent.Text12 = me![Stock Number]

FYI you have StockNumber and Stock Number.
Any chance you are messing that up in the linking?
 
Last edited:

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
FYI,
You can simply link the subforms directly as @ebs17 . I usually do the trick I showed using the first forms on current event. Because you still have to write some code to refresh the second subform.
In your case it would be
Code:
Link Master Fields: [Child68]![Stock Number]
Link Child Fields: [Stock Number]
(no ME or Parent in the linking)
However, I find I have to still put code in the first subform to refresh the second subform
In the first form's on current event you need something like
me.parent.SecondSubform.Form.Requery

This demos both methods. Using the linking textbox like you are trying and using the direct reference to the other subform which requires a requery.
 

Attachments

  • ThreeSubsV2.accdb
    4.3 MB · Views: 72

rainbows

Registered User.
Local time
Today, 12:19
Joined
Apr 21, 2017
Messages
425
1667304906634.png

i have put the yellow lines around this form . this is where text box 12 is looking

1667305146607.png

this is where it links text12 to the stocknumber

the strange thing is it works sometimes as it does on other copies of it see below but like i said i am worried it will go wrong

1667305314911.png
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
Your problem seems obvious. Your linking is fine, but your control source for text12 returning an Error. Simply do what I said using the first subforms on current event to set the value of Text12 and be done with it.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
Also do everyone a favor before posting again, and rename all of the relevant controls to useful information! We are guessing what is what and it wastes our time trying to decipher.

TxtLink (for your linking textbox)
subFrmPurchases
subFrmStock

When I post code people can easily determine what I am doing since my controls and variables have useful names.
 

rainbows

Registered User.
Local time
Today, 12:19
Joined
Apr 21, 2017
Messages
425
i really appreciate your help with this as i am not good at this sort of thing

i dont think i have done this correctly i did this on form child68



1667306388353.png
 

CarlettoFed

Member
Local time
Today, 21:19
Joined
Jun 10, 2020
Messages
119
Perhaps it would be easier to understand if you attached the file, with a minimum of data and replacing any sensitive ones.
 

mike60smart

Registered User.
Local time
Today, 20:19
Joined
Aug 6, 2017
Messages
1,907
Perhaps it would be easier to understand if you attached the file, with a minimum of data and replacing any sensitive ones.
Hi

If you want to get the Stock Number from Subform1 you can use the following in your Text 12 Unbound Control:-

=[Forms]![purchasing form]![Child68].[Form]![Stock Number]

Rename this Control to txtStockNumber

Then to link Subform1 with Subform 2 use the following

LinkMaster field: txtStockNumber
Link Child field:StockNumber
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:19
Joined
Feb 19, 2002
Messages
43,280
Aside from the poor naming standards which everyone has already complained about, I don't see a problem.

That, and the fact that it works on one machine but not another leads me to a references issue.

The thing about reference issues which makes them so confusing is that it is the first piece of cde that errors and that is almost always not the problem.

On the machine where the code does not work ---
1. open the form in design view.
2. Open the VBA window
3. Go to Tools/References
4. Check the list for anything marked MISSING.

Possibility 2.
Maybe the file that doesn't work is corrupted. Place a new copy of the working file on the PC that isn't working.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
FYI,
Everything you did originally actually looks correct assuming all the names are correct.
=[Child68].form![stock number]
Should work. I tested that construct and it worked. Maybe try deleting the text box and recreating. Your code in the current event is wrong and not needed. The suggestion was to set text12 via code, not to modify the links.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 15:19
Joined
May 21, 2018
Messages
8,529
I see now. It is
.form![stock number]
Not
!form![stock number]
You show both
 

Users who are viewing this thread

Top Bottom