Solved

OPen form Add mode & pass data across

Posted on 2013-01-16
8
422 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
  • 4
  • 3
8 Comments
 
LVL 61

Expert Comment

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

Author Comment

by:correlate
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 31

Accepted Solution

by:
Helen_Feddema earned 500 total points
Comment Utility
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
Comment Utility
In your popup form the tempvars syntax should be

tempvars("lngEmployeeID")
0
 

Author Comment

by:correlate
Comment Utility
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
Comment Utility
Thanks for this works a treat
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now