Hello,
I have a database and I can't figure out how to take a field from a subform and then add that date into an existing table.
The frmEvent has a subform. (The subforms data is based on an un-updateable recordset from a query)
When the user clicks the EDIT button I want the EventDate from the subform to be put into the tblEventException.OrigEventDate field. The EventDate comes from a query. (qryEventDates)
I tried using an Update SQL statement but it's not working correctly::banghead:
Maybe I need to use an INSERT statement? If so how would I code that in VBA? I have zero knowledge of using SQL in VBA so i could be missing something. This code was inherited and is based on Allen Browne's recurring activities located at :allenbrowne.com/AppRecur
I have a database and I can't figure out how to take a field from a subform and then add that date into an existing table.
The frmEvent has a subform. (The subforms data is based on an un-updateable recordset from a query)
When the user clicks the EDIT button I want the EventDate from the subform to be put into the tblEventException.OrigEventDate field. The EventDate comes from a query. (qryEventDates)
I tried using an Update SQL statement but it's not working correctly::banghead:
Code:
Private Sub cmdEdit_Click()
On Error GoTo Err_Handler
Dim db As DAO.Database
Dim strSQL As String
Dim strWhere As String
strWhere = "(EventID = " & Nz(Me.EventID, 0) & ") AND (InstanceID = " & Nz(Me.InstanceID, 0) & ")"
If IsNull(Me.EventID) Or IsNull(Me.InstanceID) Then
MsgBox "Unable to determine the entry to edit.", vbExclamation, "Cannot edit."
Else
strSQL = "UPDATE tblEventException " _
& "SET OrigEventDate = #" & Forms!frmEvent!frmEventSub!EventDate & "# " _
& "WHERE " & strWhere
Debug.Print strSQL
CurrentDb.Execute strSQL, dbFailOnError
DoCmd.OpenForm "frmEventException", WhereCondition:=strWhere, WindowMode:=acDialog
End If
Exit_Handler:
Exit Sub
Err_Handler:
Call LogError(Err.Number, Err.Description, conMod & ".cmdEdit_Click")
Resume Exit_Handler
End Sub
Maybe I need to use an INSERT statement? If so how would I code that in VBA? I have zero knowledge of using SQL in VBA so i could be missing something. This code was inherited and is based on Allen Browne's recurring activities located at :allenbrowne.com/AppRecur