Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

OPen form Add mode & pass data across

Posted on 2013-01-16
Last Modified: 2013-01-17
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?
Question by:correlate
  • 4
  • 3
LVL 61

Expert Comment

ID: 38783147
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

LVL 61

Expert Comment

ID: 38783151
If you are using Access 2007 or higher you can also use TempVars for this:
LVL 61

Expert Comment

ID: 38783178
Here's another article about TempVars:


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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.


Author Comment

ID: 38783308

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?
LVL 31

Accepted Solution

Helen_Feddema earned 500 total points
ID: 38783798
Or you can just set lngEmployeeID from the current record on the initial form, and set a control on the popup form to it.  Something like this (BTW, I recommend using the named argument syntax, for clarity):

Private Sub cmdOpenPopup_Click()

   Dim frm As Access.Form
   Dim lngEmployeeID As Long
   lngEmployeeID = Me![EmployeeID]
   DoCmd.OpenForm FormName:="frmPopup"
   Set frm = Forms("frmPopup")
   frm![txtEmployeeID].Value = lngEmployeeID
End Sub

Open in new window

LVL 61

Expert Comment

ID: 38783821
In your popup form the tempvars syntax should be


Author Comment

ID: 38783851
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

Author Closing Comment

ID: 38787064
Thanks for this works a treat

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
On Key Down Access 2010 6 41
table joins in qry 17 61
90 days before current date 12 32
Treeview control in 64 bit Office. 2 23
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question