Link to home
Start Free TrialLog in
Avatar of BuddyKing60626
BuddyKing60626

asked on

Change a textbox in a Subform based on the value of a combobox on the mainform

I have attempted to address this with endless changes of periods and exclamation points, .Form, .Mainform, .Subform, to no avail. Here is the code at the moment that doesn't change the text in the textbox Text41 and also does not place the value of Author in the main form in the corresponding field in the subform based on a Combobox, Frame59. Suggestions are appreciated.

If Me.Frame59 = "2" Then
Me.Anthologies.Visible = True
Me.Anthologies.Form.Text41.ControlSource = "Anthology"
Else
If Me.Frame59 = "3" Then
Me.Anthologies.Visible = True
Me.Anthologies.Text41.Value = "Collection"
Me.Author = Form.Author
Else
If Me.Frame59 = "1" Or "4" Then
Me.Anthologies.Visible = False
End If
End If
End If
End Sub
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

Not sure what is parent form and subform, but try this:

If Me!Frame59 = "2" Then
    Me!Anthologies.Visible = True
    Me!Anthologies.Form!Text41.Value = "Anthology"
ElseIf Me!Frame59 = "3" Then
    Me!Anthologies.Visible = True
    Me!Anthologies.Form!Text41.Value = "Collection"
    Me.Author = Me!Anthologies.Form!Author.Value
ElseIf Me!Frame59 = "1" Or Me!Frame59 = "4" Then
    Me.Anthologies.Visible = False
End If

Open in new window

/gustav
Check structure of your DB. It is not good idea to store text instead of reference to other table. Look at sample
DB29040429.accdb
Please define the problem, as Main Form: name, recordsource, relevant controls. Do the same for subform.
Location of the code.
Form.Control: Refers to the form where the code runs.

Me.Author = Form.Author for example, assigns Author field value of the current form to itself.

If in a form, Me and Form refer to the same form. The same with Me and Report which refers to the same report.
But Me is preferable, because it evaluates to Form if in form, or to Report if in report.

If issued in Main form to assign Subform's Author field to main's Author field
Me.Author = SubformControl.Form.Author

You need to specify the code location, and field location in order to properly reference the involved controls.

Object.aProperty may lead to an Object.
So,
Me.f1.name gives the name property of the object f1, which is a property of the Me object
I admit it is very confusing at start.
Avatar of BuddyKing60626
BuddyKing60626

ASKER

I really do apologize for lack of preparation in posting this. I used to do a lot of Access work, but haven't for a few years and I promised a database to a small library that has limited requirements. I regret the lack of naming considerations and my only excuse is trying to make this work for several days and many hours making me crazier than I am on a daily basis.
Main Form Name: NewEnter
Database: Lonergan
Subform Name: Anthologies
Database: Anthologies
The relationship is Lonergan, one to many Anthologies.
The relationship fields are: Lonergan - BookID and Anthologies - MatchingRecord
The Event takes place on Frame59 (Combobox) After Update
The textbox is Text41
The comboBox (Frame59) choices are: 1 Scripts, 2 Anthologies, 3 Collections and 4 Other.
Anthologies should be named more appropriately since it contains titles of both anthologies and collections. The Anthology subform is only visible if the mainform combo box (Frame59) equals 2 (Anthologies) or 3 (Collections). If it is 2 (Anthologies) I want the Author field from NewEnter to populate all the Author fields of the Subform (Anthologies) since the author will always be the same. If it is 3 (Collections), each author will be unique.
What I am trying to do here is populate a textbox in the subform (Anthologies) with the result of the Combobox (Frame59). That textbox is in the header of the subform and, in theory, will help whoever is doing input remember where they are and what they are about.
The suggestion from Gustav cleaned things up with "ElseIf", but has already been tried and without effect. Maybe I am not aware of the correct control to address for a textbox (Value, =, Control Source) and when typing the code, Text41 is not in the choices.
Please help us, to save time, by uploading a sample database.
Walk us through the database to demonstrate the problem.
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry about the delay, was attending to family illness in another state without internet. This method allows me to access locations and values that I have read various statements about, depending on the Access release. Thanks for the help.