Link to home
Start Free TrialLog in
Avatar of SteveL13
SteveL13Flag for United States of America

asked on

How populate a 3rd form with the value typed into a combobox on a sub-form?

I have a main form that has a subform that has a combobox.  The properties of the combobox are... Limit to List = Yes, Allow Value List Edits = Yes.  And then I have another form, the third form, that opens when the user answers Yes to adding a record.

When that 3rd form opens, I want a field on it to be populated with the value I typed in the combobox on the subform.

Can this be done?
Avatar of SteveL13
SteveL13
Flag of United States of America image

ASKER

I forgot to mention, the subform is a continuous form so the value to be populated has to be from the record on the continuous form that is being edited.
ASKER CERTIFIED SOLUTION
Avatar of Sheils
Sheils
Flag of Australia 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
I'm sure I'm doing something wrong because this isn't working.

Is there a way to do this with TempVars?  Set the value as a temp var and use it to populate the field in the 3rd form?
Yes there is.

On the change event of the combobox you can insert the following codes

In a module declare the variables as global eg:

Global Var1 as string
Global Var2 as Long
Global Var3 as Double

Var1=field1
Var2=field2
Var3=field3

Then you can use some other even to add these value to your third form
posting a sample of your db with some dummy data will allow me to better assist you
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America 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
Scott,

Isn't working.  I have this in the notinlist of the combobox:

Sub cboItemN_NotInList(NewData As String, Response As Integer)
   
   '/ open the second form in dialog mode
   DoCmd.OpenForm "frmWorkOrderItemsAddMode", , , , , acDialog, NewData
   
   Response = acDataErrAdded

End Sub

Open in new window


And this in the onopen event of the 3rd form:

Private Sub Form_Open(Cancel As Integer)

    Me.txtDescription = Me.OpenArgs

    DoCmd.Restore

End Sub

Open in new window


I also tried:  Me.Description = Me.OpenArgs  instead of the field name.  Is the control name.
Ok.  I do have the combobox adding the new record to the table.  And I do have the 3rd form opening with NewData in the first field which is perfect.  But when I add data to the other fields on the 3rd form this other data is not being added to the new record created by the combobox.  

??
SOLUTION
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
But when I add data to the other fields on the 3rd form this other data is not being added to the new record created by the combobox.  
That's not really what you asked. The NotInList event is used to add a value to the Combobox that raises that event. If your intent is to add an entirely new RECORD, then I'd suspect you're going about this the wrong way.

But your question is too "scatter-shot" to really understand, so you'll have to simplify things for us.

Do you want to add a new record the the COMBO?

Or do you want to add a new record, and include a value typed into the COMBO?
I want to type a value in the combo and if the record exists use it as usual.  If it doesn't exist ask the user if the want to add it and if they say Yes, open a form that allows them to enter the details of the new record.  When they close that form, return them to the form with the combo, requery the come with the added record, and go on from there.
Then the NotInList event should work. That's exactly what it's designed for - adding a new record to the Recordsource of the COMBO. It will not add a new record to the Form on which the combo lives, however.

You have to be sure to dot all the I's and cross all the T's with this method. For example, on your 3rd form, you must be sure that you're saving all the data correctly, and that it's being saved to the same recordsource as your combo is using, and if the data is "child" data, that you're properly relating the Child data to the Parent.

You also have to be sure to set the Response value correctly.
In your original question you said "When that 3rd form opens, I want a field on it to be populated with the value I typed in the combobox on the subform."

The notinlist codes will add the new data to you combobox row source but not to the third form record source. To do this you still need to run the insert into query which I referred to previously

Private Sub ComboBoxName_Change()

Dim lngID as Long
Dim strSQL as String

StrSQL="INSERT INTO TableA (field1, field2, field3) "
StrSQL=StrSQL & "VALUES (" & chr(34) & Me.fleild1 & chr(34) & "," &  chr(34) & "," & chr(34) & Me.fleild2 & chr(34) & "," & chr(34) & "," & Me.fleild3 & ") "

Currentdb.Execute strSQL

End Sub

I believe that the onchange event occurs after the notinlist (our expert please correct me if this is wrong) so it should work even when the notinlist is triggered.
SOLUTION
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
To all that offered support...  I found this web site and used solution #2.  I'm sure you all suggested a solution muc hlike this...

https://support.microsoft.com/en-us/kb/197526