Transfer Text Box value from Popup form to Subform (1 Viewer)

lasse.staalung

New member
Local time
Today, 03:48
Joined
Aug 16, 2017
Messages
5
I have a main form with a subform in table view, and a popup continuous form. The reason for the continuous form, is to show the product picure also. I have products in two dimensions, product number and color.
What I want is to send a ColourID from the Popup form to the Subform.
My main form is named "Shop_Orders", my subform "Shop_Order_Detail_Extended" and my popup form Shop_ColorPick.
The Text Box name in the Subform is “Colour” (Old spelling mistake) and in the Pop Up form “ColorNo”
I have tried following vba codes in the event Doubble Click under the Popup Form Text Box “ColorNo” with no success:
[Shop_Order_Detail_Extended].Form![Colour] = ColorNo
Me.[Shop_Order_Detail_Extended].Form![Colour] = Me.ColorNo
Me!Shop_Order_Detail_Extended.Form.Colour = Me.ColorNo
Me.Parent.Shop_Order_Detail_Extended.Form!Colour = Me.ColorNo
Me.Parent.Shop_Order_Detail_Extended!Colour = Me.Colour
Me.[Shop_Orders].Form![Shop_Order_Detail_Extended].Form![Colour] = ColorNo
Parent.Forms!Shop_Orders.[Shop_Order_Detail_Extended].[Colour] = ColorNo
[Forms]![Shop_Orders]![Shop_Order_Detail_Extended].Colour = ColorNo
From a Text Box named “ColorNo” on the Main form this code, works fine:
[Shop_Order_Detail_Extended].Form![Colour] = ColorNo
But from the popup form to Main form this code does not work:
[Shop_Orders].Form![ColorNo] = ColorNo
The eroor message I get is:
Run-time error '2465':
Shop V4.0 cant find he field '|1' reffered to in your expression.
I have tried something about Navigation form and Navigation Subform also, but I am not sure I understand that right.
I am out of ideas, so I would really appreciate some guiding.
Thank you in advanced.
 

Cronk

Registered User.
Local time
Today, 20:48
Joined
Jul 4, 2013
Messages
2,772
To refer to a control on a sub form, use the syntax
Forms!ParentFormName!SubformControlName.form.control

In your case, something like
Forms!Shop_Orders.sfShop_Order_Detail_Extended.Form.Colour=Me.ColorNo

Incidentally, you could make your posts more easy to read by breaking the text into a few paragraphs.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:48
Joined
May 7, 2009
Messages
19,230
First add this to a Standard Module:
Code:
Public Function isFormLoaded(ByVal strFormName As String) As Boolean
    Dim oAccessObject As AccessObject
    On Error Resume Next
    Set oAccessObject = CurrentProject.AllForms(strFormName)
    isFormLoaded = False
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then isFormLoaded = True
    End If
    Set oAccessObject = Nothing
End Function

try this on the DoubleClick Event of your Shop_ColorPick Pop up form:

Code:
Private Sub ColorNo_DblClick(Cancel As Integer)
'check first if Shop_Orders form is loaded
If IsFormLoaded("Shop_Orders") Then
	'it is loaded so insert ColorNo to Colour field of subform
	Forms!Shop_Orders!Shop_Order_Detail_Extended.Form!Colour = Me!ColorNo
	'you may also elect to do this
	Forms!Shop_Orders!Shop_Order_Detail_Extended.Form.Dirty = False
End If
End Sub
 

lasse.staalung

New member
Local time
Today, 03:48
Joined
Aug 16, 2017
Messages
5
To refer to a control on a sub form, use the syntax
Forms!ParentFormName!SubformControlName.form.control

In your case, something like
Forms!Shop_Orders.sfShop_Order_Detail_Extended.Form.Colour=Me.ColorNo

Incidentally, you could make your posts more easy to read by breaking the text into a few paragraphs.

Worked perfect. Thank you, you saved my day.:cool:

Ps: I changed two typing mistakes to your code:
Forms!Shop_Orders.Shop_Order_Detail_Extended.Form.Colour=Me.ColorNo
 
Last edited:

lasse.staalung

New member
Local time
Today, 03:48
Joined
Aug 16, 2017
Messages
5
First add this to a Standard Module:
Code:
Public Function isFormLoaded(ByVal strFormName As String) As Boolean
    Dim oAccessObject As AccessObject
    On Error Resume Next
    Set oAccessObject = CurrentProject.AllForms(strFormName)
    isFormLoaded = False
    If oAccessObject.IsLoaded Then
        If oAccessObject.CurrentView <> acCurViewDesign Then isFormLoaded = True
    End If
    Set oAccessObject = Nothing
End Function

try this on the DoubleClick Event of your Shop_ColorPick Pop up form:

Code:
Private Sub ColorNo_DblClick(Cancel As Integer)
'check first if Shop_Orders form is loaded
If IsFormLoaded("Shop_Orders") Then
	'it is loaded so insert ColorNo to Colour field of subform
	Forms!Shop_Orders!Shop_Order_Detail_Extended.Form!Colour = Me!ColorNo
	'you may also elect to do this
	Forms!Shop_Orders!Shop_Order_Detail_Extended.Form.Dirty = False
End If
End Sub

This solution worked perfect too. You guys are good. Thank you! :cool:
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:48
Joined
Jan 20, 2009
Messages
12,851
Ps: I changed two typing mistakes to your code:
Forms!Shop_Orders.Shop_Order_Detail_Extended.Form.Colour=Me.ColorNo

Cronk did say "something like .... ". We often post approximations of the code you will need. In this case Cronk was clarifying the reference as a subform with the prefix "sf", probably in line with his own naming conventions.

The extra space "mistake" was inserted by the forum. It does this automatically to break up long lines of text which could otherwise push the right margin of the whole page right off the screen. It is one reason why code should always be posted inside code tags, particularly if it exceeds 50 characters without a space.

The real mistake I see is with your object naming. I don't mind the use of "color" or "colour" but you have mixed the US and English spellings in the same project, even in same line of code which is bound to lead to mistakes. (Note I am not referring to the "color" used in property names which is always US regardless of the regional setting.)

I would also recommend you drop the use of underscores in object names. Firstly they break up the text in ways that make it much harder to read because the underscore is a stronger gap than the dot or bang. Secondly the underscore already has a purpose to separate object names from their event names in VBA code.
 

Users who are viewing this thread

Top Bottom