Solved

Access code to copy field from one form to another form

Posted on 2013-01-17
6
1,922 Views
Last Modified: 2013-01-17
In Access 2010 I have a form named frmTimeOff.  In the form I have the following fields.

EmpInit  |  DateOff  |  Hours  |  Comments

I also have a table name Calendar which is a link to a SharePoint Calendar.  From this table I created a form named frmCalendar.

The frmCalendar has the following fields.

Title  |  Start Time  

I placed a Command button in the frmTimeOff form so when clicked it copies the record from the frmTimeOff form to a record in the frmCalendar.  Note the frmTimeOff form is a Continuous form so I have a button next to each record.

I've tried different variations of the following code, but can't get anything to work.  Note I'm only showing copying one field for this example.

Private Sub cmdUpdate_Click()
  Dim intCopyNum As Variant
    intCopyNum = Me.DateOff.Value
      DoCmd.Close
        Forms!frmCalendar.Form.Start_Time.Value = intCopyNum
End Sub

Can anyone help me with this?

Thanks in advance!
0
Comment
Question by:Senniger1
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38786990
Try closing the form after you assign instead of before.
Forms!frmCalendar.Form.Start_Time.Value =intCopyNum
DoCmd.Close

Open in new window

0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 38787015
Also, have you tried this?
Forms!frmCalendar.Form.Start_Time.Value = Me.DateOff.Value
0
 

Author Comment

by:Senniger1
ID: 38787034
I tried both of your suggestions assuming you wanted me to add the line you gave to the rest of my code.  Neither worked.  
Dim intCopyNum As Variant
intCopyNum = Me.DateOff.Value
Forms!frmCalendar.Form.Start_Time.Value = intCopyNum
DoCmd.Close

Dim intCopyNum As Variant
intCopyNum = Me.DateOff.Value
Forms!frmCalendar.Form.Start_Time.Value = Me.DateOff.Value
DoCmd.Close

I get the same time of error as all the variations I've tried.  The error is a runtime errors...
Run-time error '2450' - Employee Time Card cannot find the referenced form 'frmCalendar'.

The form is there and I've checked the spelling and everything is correct.

Any other ideas?  Thanks!
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 29

Accepted Solution

by:
IrogSinta earned 500 total points
ID: 38787104
I just noticed an error in your syntax. Try this:
Private Sub cmdUpdate_Click()
    Forms!frmCalendar.Start_Time.Value = Me.DateOff.Value
    DoCmd.Close
End Sub

Open in new window

0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 38787536
What are the data types of the fields?
0
 

Author Closing Comment

by:Senniger1
ID: 38788064
Turns out it wasn't the code causing the issue.  Looking up the runtime error of 2450 showed I needed to have the frmCalendar open before running the code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
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…
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…

929 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

14 Experts available now in Live!

Get 1:1 Help Now