Link to home
Start Free TrialLog in
Avatar of Tom Crowfoot
Tom CrowfootFlag for United Kingdom of Great Britain and Northern Ireland

asked on

OPen form Add mode & pass data across

Dear Experts,

I want to be able to open up a pop up form to add data, and also populate 1 field from the original form:

The forms & fields are as follows:

The form from which the pop up is launched is "Employee" & has a field [EmployeeID] which I want to to take across to the pop up form.

The pop up form is "AddHRLog" & the field to be populated is [EmployeeID]

So basically when the pop up opens it fills in EmployeeID with the details from Employee.EmployeeID

I have got this far ...

DoCmd.OpenForm "AddHRLog", , , , acFormAdd

Open in new window


Can anybody help?
Avatar of mbizup
mbizup
Flag of Kazakhstan image

DoCmd.OpenForm "AddHRLog", , , , acFormAdd, OpenArgs := Me.EmployeeID

Open in new window


And in the open event of your popup form:

Me.EmployeeID = OpenArgs

Open in new window

If you are using Access 2007 or higher you can also use TempVars for this:
http://blogs.msdn.com/b/thirdoffive/archive/2006/04/13/570539.aspx
Here's another article about TempVars:

http://blogs.office.com/b/microsoft-access/archive/2010/09/27/power-tip-maximize-the-user-of-tempvars-in-access-2007-and-2010.aspx

I don't have Access 2007 handy but I believe the syntax in your case would be:

TemVars.Add "lngEmployeeID", Me.EmployeeID
DoCmd.OpenForm "AddHRLog", , , , acFormAdd

Open in new window


And in the popup form's Open Event:
Me.EmployeeID = TempVars("lngEmployeeID")

Open in new window

Avatar of Tom Crowfoot

ASKER

Hi

Thanks for this - am struggling to get this to work:

In the 1st form I have ...

TempVars.Add "lngEmployeeID", Me.EmployeeID.Value
DoCmd.OpenForm "AddHRLog", , , , acFormAdd]

Open in new window


I have added in the .Value as I was getting an error saying "TempVars can only store data. They cannot store objects"

I'm not sure if it makes a difference but both fields are numbers

In the pop up form I have...
Private Sub Form_Open(Cancel As Integer)
Me.EmployeeID = TempVars!lngEmployeeID
End Sub

Open in new window


Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of Helen Feddema
Helen Feddema
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
In your popup form the tempvars syntax should be

tempvars("lngEmployeeID")
Hi both
thanks for these - I'll give them both a go in the morning when I'm back at the PC - I'll double check, but I think I tried that syntax from mbizup, but will give it a go again
Thanks for this works a treat