Solved

OPen form Add mode & pass data across

Posted on 2013-01-16
8
449 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
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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

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

Back Up Your Microsoft Windows Server®

Back up 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.

Question has a verified solution.

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

Suggested Solutions

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

777 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