Afternoon all.
My database keeps records of shifts worked. The form which is used to input the data has drop down boxes to select Contract, Site, Name, etc. The user enters this data from the time sheets. Each shift record can be the same for each day of the week. I'm trying to code a way of copying data from an existing record and pasting into a new record on the click of a button so only the date has to be changed, to save inputting time, using this code:
Private Sub CmdCopyRecord_Click()
On Error GoTo Err_CmdCopyRecord_Click
Dim StrShiftDate As String
Dim StrSiteID As String
Dim StrStaffID As String
Dim StrStaffTypeID As String
StrShiftDate = ShiftDate.Text
StrSiteID = SiteID.Value
StrStaffID = StaffID.Value
StrStaffTypeID = StaffTypeID.Value
DoCmd.GoToRecord , , acNewRec
ShiftDate.Text = StrShiftDate
SiteID.Value = StrSiteID
StaffID.Value = StrStaffID
StaffTypeID.Value = StrStaffTypeID
Exit_CmdCopyRecord_Click:
Exit Sub
Err_CmdCopyRecord_Click:
MsgBox Err.Description
Resume Exit_CmdCopyRecord_Click
End Sub
When the button is clicked I get the error message "You can't reference a property or method for a control unless the control has the focus".
If I rem out the ShiftDate.Txt lines the code works lovely. This control is a text box, the ones that do work are combo boxes.
Can anyone please give me a pointer on how to make this work for the date field text box too.
Cheers
Thanks
Regards
Tyler
My database keeps records of shifts worked. The form which is used to input the data has drop down boxes to select Contract, Site, Name, etc. The user enters this data from the time sheets. Each shift record can be the same for each day of the week. I'm trying to code a way of copying data from an existing record and pasting into a new record on the click of a button so only the date has to be changed, to save inputting time, using this code:
Private Sub CmdCopyRecord_Click()
On Error GoTo Err_CmdCopyRecord_Click
Dim StrShiftDate As String
Dim StrSiteID As String
Dim StrStaffID As String
Dim StrStaffTypeID As String
StrShiftDate = ShiftDate.Text
StrSiteID = SiteID.Value
StrStaffID = StaffID.Value
StrStaffTypeID = StaffTypeID.Value
DoCmd.GoToRecord , , acNewRec
ShiftDate.Text = StrShiftDate
SiteID.Value = StrSiteID
StaffID.Value = StrStaffID
StaffTypeID.Value = StrStaffTypeID
Exit_CmdCopyRecord_Click:
Exit Sub
Err_CmdCopyRecord_Click:
MsgBox Err.Description
Resume Exit_CmdCopyRecord_Click
End Sub
When the button is clicked I get the error message "You can't reference a property or method for a control unless the control has the focus".
If I rem out the ShiftDate.Txt lines the code works lovely. This control is a text box, the ones that do work are combo boxes.
Can anyone please give me a pointer on how to make this work for the date field text box too.
Cheers
Thanks
Regards
Tyler