Hello,
How can I add a new record in a Subform that is generated from a button on the Parent form...? Then set textboxes on the Subform to values from code...?
Previously, I was able to accomplish this when all the textboxes where on the same form based on the same table; however, I have created a one -> many relationship so I could take a snapshot of the currrent date/time and # hours worked (textbox fields) for each time the employee was called, declined or worked overtime.
I was attempting to utilize the following code snippet to update the Subform fields so they would create a new record and store it in the underlying table...
This is where I thought I should create a new record and then fill the fields with the appropriate data...
Any direction appricated,
Jim
How can I add a new record in a Subform that is generated from a button on the Parent form...? Then set textboxes on the Subform to values from code...?
Previously, I was able to accomplish this when all the textboxes where on the same form based on the same table; however, I have created a one -> many relationship so I could take a snapshot of the currrent date/time and # hours worked (textbox fields) for each time the employee was called, declined or worked overtime.
I was attempting to utilize the following code snippet to update the Subform fields so they would create a new record and store it in the underlying table...
I'm also getting a wrong datatype error for the line w/ DoCmd.GoToRecord...Private Sub cmdEmployeeDeniedButton_Click()
Dim myMsg As String
Dim otTimeStamp As String
Dim otDate As Date
otTimeStamp = Format(Date, "Long Date") & " " & Format(Time(), "Long Time")
otDate = Forms!frmOvertime![txtOT_Date]
If Forms!frmOvertime![txtOT_Hours] <= 0 Then
myMsg = MsgBox("The Overtime Hours are set to 0" & (Chr(13)) & "Please enter the number of hours!", vbCritical, "Missing Hours")
Forms!frmOvertime!txtOT_Hours.SetFocus
Else
Forms!frmOvertime!frmListByTotalHours!txtTotal_OT_Hours = (Forms!frmOvertime!frmListByTotalHours![txtTotal_OT_Hours] + Forms!frmOvertime![txtOT_Hours])
'Need to create a new record for next variables
'Forms!frmOvertime!frmListByTotalHours!frmOvertime.SetFocus
DoCmd.GoToRecord acActiveDataObject, frmPersonnelOvertime, acNewRec
Forms!frmOvertime!frmListByTotalHours!frmPersonnelOvertime![txtDenied_OT_Date] = otTimeStamp
Forms!frmOvertime!frmListByTotalHours!frmPersonnelOvertime![txtDenied_OT_Hours] = Forms!frmOvertime![txtOT_Hours]
myMsg = "Data has been Modified!"
myMsg = myMsg & (Chr(13)) & "Do wish to Save the Changes?"
myMsg = myMsg & (Chr(13)) & "Click YES to Save or No to Discard Changes."
If MsgBox(myMsg, vbQuestion + vbYesNo, "Save Changes?") = vbYes Then
DoCmd.Save
Me.Requery
Else
DoCmd.RunCommand acCmdUndo
End If
End If
End Sub
This is where I thought I should create a new record and then fill the fields with the appropriate data...
Any direction appricated,
Jim