I have a form with field [Comments] and a command button that opens a form with unbound field [EnterComments]. This command button is set to open to the same record on the original form (I chose this setting in the wizard). The second form has command button [close form]in addition to the unbound field [EnterComments]. The second form also has the record number and name of subject person from the first form. I have the following on the on click event of the [close form] button:
Private Sub CloseCommentFormbutton_Click()
On Error GoTo Err_CloseCommentFormbutton_Click
[EnterComments].SetFocus
If IsNull(EnterComments) Then
DoCmd.Close
Else
EnterComments = EnterComments.Text
RNComment = Now() & ": " & EnterComments.Text & " " & Chr(13) & Chr(10) & RNComment
EnterComments = " "
DoCmd.Close
End If
Exit_CloseCommentFormbutton_Click:
Exit Sub
Err_CloseCommentFormbutton_Click:
MsgBox Err.Description
Resume Exit_CloseCommentFormbutton_Click
End Sub
This then feeds the comments from the unbound [EnterCommetnts] on the second form to the [Comments] field on the first field and closed the second form.
This works fine for me except for one thing: When I click the open form command button on the original field, the second form opens, but to no particular record. The record number and name fields are empty and if I enter comments and then click the close form button, the comments don't feed over.
However, if I save the record on the original form first by moving to another record or clicking F9, the feed function on the second form works perfectly. Clicking F9 before clicking the command button seems a little cheesy to me. Can anyone recommend something to make it a little more professional by making saving the record part of the on click event for the open form button on the firs form?
Private Sub CloseCommentFormbutton_Click()
On Error GoTo Err_CloseCommentFormbutton_Click
[EnterComments].SetFocus
If IsNull(EnterComments) Then
DoCmd.Close
Else
EnterComments = EnterComments.Text
RNComment = Now() & ": " & EnterComments.Text & " " & Chr(13) & Chr(10) & RNComment
EnterComments = " "
DoCmd.Close
End If
Exit_CloseCommentFormbutton_Click:
Exit Sub
Err_CloseCommentFormbutton_Click:
MsgBox Err.Description
Resume Exit_CloseCommentFormbutton_Click
End Sub
This then feeds the comments from the unbound [EnterCommetnts] on the second form to the [Comments] field on the first field and closed the second form.
This works fine for me except for one thing: When I click the open form command button on the original field, the second form opens, but to no particular record. The record number and name fields are empty and if I enter comments and then click the close form button, the comments don't feed over.
However, if I save the record on the original form first by moving to another record or clicking F9, the feed function on the second form works perfectly. Clicking F9 before clicking the command button seems a little cheesy to me. Can anyone recommend something to make it a little more professional by making saving the record part of the on click event for the open form button on the firs form?