Pre-populating a field in new form

  • Thread starter Thread starter John
  • Start date Start date
J

John

(Access XP) I have a Company form with a subform containing a list of
Employees in the Company. The Employee list subform also contains an Add
button if the user wants to add a new Employee to the Company. It opens a
new Employee form then when that form is saved, it returns to the original
Company form and the new Employee shows up in the subform list of Employees.

I would like to pre-populate the CompanyID field in the new Employee form
(the link field between the two forms) when a new Employee form is opened
from within the Employee list subform but I can't figure out how to do it.

This is the openform code I'm using:

DoCmd.OpenForm strFormName, , , , acFormAdd, acDialog, "GotoNew"

The CompanyID is obviously in the Company form but I can't figure out how to
send it to the new Employee form.

Thank you very much. Any ideas greatly appreciated.

Penn
 
I would suggest that the companyId be passed across as part
of the OpenArgs. The method that I use when passing
multiple arguments is to seperate them with vbCrLf (as this
is unlikely to ever be part of a meaningful argument). The
arguments can then be seperated by using the Split
function. For example, in the Form's Load eventhandler, I
would have code along the lines of

Dim strOpenArgs() As String

strOpenArgs = Split(OpenArgs, vbCrLf)

The strOpenArgs(0) will contain the first argument ,
strOpenArgs(1) the second and so on.

Hope This Helps
Gerald Stanley MCSD
 
Back
Top