Kevin
asked on
Pass new Form Value to the form that opened it
Access 2013. I have two tables - CompanyInfo & EmployeeInfo. A company can have multiple employees.
I have a form EmployeeInput where the use can PICK the EXISTING company that a new employee works for from a Combo box of CompanyNames. The user can double click the combobox if the Company doesn't exist, and the CompanyInput form will open and let the user enter all the information about this new company. I have a button on the CompanyInput form to save the record and close the form "to return to employee input". When the CompanyInput form closes, I would like for the combobox on the EmployeeInput form which PREVIOUSLY did not contain the CompanyName to now SHOW the CompanyName that was just created on the CompanyInput form, along with the address, phone number, and other information from the company that was created.
I have seen some things that looked like what I needed, but so far have not been able to get it to work.
Thanks for any and all help!
I have a form EmployeeInput where the use can PICK the EXISTING company that a new employee works for from a Combo box of CompanyNames. The user can double click the combobox if the Company doesn't exist, and the CompanyInput form will open and let the user enter all the information about this new company. I have a button on the CompanyInput form to save the record and close the form "to return to employee input". When the CompanyInput form closes, I would like for the combobox on the EmployeeInput form which PREVIOUSLY did not contain the CompanyName to now SHOW the CompanyName that was just created on the CompanyInput form, along with the address, phone number, and other information from the company that was created.
I have seen some things that looked like what I needed, but so far have not been able to get it to work.
Thanks for any and all help!
ASKER
So
1. me.controlname.requery would be the last line in the code that Opened the second form for input?
2. I would put the parameters that I wanted passed (such as address, city, state, country) and then just add acDialog as the last parameter?
1. me.controlname.requery would be the last line in the code that Opened the second form for input?
2. I would put the parameters that I wanted passed (such as address, city, state, country) and then just add acDialog as the last parameter?
1. no, controlname is what you want to requery -- that would be the NAME property for the control containing company
To find this out: go to the DESIGN view of the form
show the property sheet if it is not already showing by pressing ALT-ENTER
(the property sheet shows additional details for whatever is selected)
then click on the control with company and get the Name from the first property listed on the OTHER (or ALL) tab
2. yes, count the commas -- or just keep pressing comma until Intellisense shows acDialog as a parameter ;)
to make Intellisense show if it doesn't launch automatically, press Ctrl-Spacebar
To find this out: go to the DESIGN view of the form
show the property sheet if it is not already showing by pressing ALT-ENTER
(the property sheet shows additional details for whatever is selected)
then click on the control with company and get the Name from the first property listed on the OTHER (or ALL) tab
2. yes, count the commas -- or just keep pressing comma until Intellisense shows acDialog as a parameter ;)
to make Intellisense show if it doesn't launch automatically, press Ctrl-Spacebar
ASKER
This was my code on the form to add company data:
which gave me a blank form for a new record. When I added the commas and the acDialog to the statement, the form did open, but was populated with a company, instead of being ready for a new record...
Private Sub cboCompanyName_DblClick(Cancel As Integer)
Dim rs As DAO.Recordset
Dim strWhere As String
Const strcTargetForm = "CompanyInputNoEmployee"
'Set up to search for the current customer.
If Not IsNull(Me.CompanyName) Then
strWhere = "CompanyName = """ & Me.CompanyName & """"
End If
'Open the editing form.
If Not CurrentProject.AllForms(strcTargetForm).IsLoaded Then
DoCmd.OpenForm strcTargetForm
End If
With Forms(strcTargetForm)
'Save any edits in progress, and make it the active form.
If .Dirty Then .Dirty = False
.SetFocus
If strWhere <> vbNullString Then
'Find the record matching the combo.
Set rs = .RecordsetClone
rs.FindFirst strWhere
If Not rs.NoMatch Then
.Bookmark = rs.Bookmark
End If
Else
'Combo was blank, so go to new record.
RunCommand acCmdRecordsGoToNew
End If
End With
Set rs = Nothing
End Sub
which gave me a blank form for a new record. When I added the commas and the acDialog to the statement, the form did open, but was populated with a company, instead of being ready for a new record...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
you're welcome ~ happy to help
Open in new window
well, you may have parameters -- in which case, do not leave those arguments blank -- main thing is to specify acDialogthis means control will not be passed back to the calling code until the form is closed.
then:
Open in new window
WHEREcontrolname is the NAME property of the combo to rebuild the list for