Link to home
Start Free TrialLog in
Avatar of Senniger1
Senniger1

asked on

Access code to copy field from one form to another form

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!
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

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

Open in new window

Also, have you tried this?
Forms!frmCalendar.Form.Start_Time.Value = Me.DateOff.Value
Avatar of Senniger1
Senniger1

ASKER

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!
ASKER CERTIFIED SOLUTION
Avatar of IrogSinta
IrogSinta
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What are the data types of the fields?
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.