Solved

OPen form Add mode & pass data across

Posted on 2013-01-16
8
469 Views
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?
0
Comment
Question by:correlate
[X]
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
  • 4
  • 3
8 Comments
 
LVL 61

Expert Comment

by:mbizup
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

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38783151
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
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38783178
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

0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 

Author Comment

by:correlate
ID: 38783308
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?
0
 
LVL 31

Accepted Solution

by:
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

0
 
LVL 61

Expert Comment

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

tempvars("lngEmployeeID")
0
 

Author Comment

by:correlate
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
0
 

Author Closing Comment

by:correlate
ID: 38787064
Thanks for this works a treat
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

739 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