Can't save record after change

G

Guest

I have a database to keep track of recommendations that are made for system
improvements within the company. The first step in the process is to make
the recommendation, which involves completing four fields. After making the
recommendation the user can click a command button to send an e-mail to the
manager advising him that a recommendation has been made. In the code that
follows I have for purposes of this posting left out error handling,
procedure title, End Sub, and so forth.

Click event for command button to send e-mail:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.SendObject,,,,,,,"Recommendation on " & [txtDate]

In order to stop the user from saving a record without all of the fields
completed, this is the Before Update event for the form (I will use just 2
fields for the example):

If IsNull([txtName]) Then
Me.txtName.SetFocus
Call Validate
Cancel = True
ElseIf IsNull([txtDate]) Then
Me.txtDate.SetFocus
Call Validate
Cancel = True
End If

"Validate" is a sub that produces an OK only message box.

If a control is empty the code sends the user back to that ocntgrol as
intended. If the blank control was txtDate, and the user fills in the date
and clicks the e-mail command button, the e-mail message, which includes
[txtDate] in the messsage body, does not show anything where [txtDate] should
be. However, if the user clicks or tabs out of the control before clicking
the e-mail button, [txtDate] shows up in the message body as intended.
How can I emulate in code the simple effect of clicking outside the field?
I expect I need to back up and execute acCmdSaveRecord again, but if so I
cannot figure out how.
Training users to go perform the extra step of exiting the field is not an
option I am willing to consider unless there is absolutely no choice. This
kind of situation comes up often enough that I would really like to find a
solution.
 
A

Allen Browne

You can SetFocus to another control if you wish to move out of txtDate.
However this doesn't make sense to me: if the user has clicked on the
command button, then it has focus and not txtDate.

Is your intention to always fire off an email, whenever a new record is
saved? If so, could use use the AfterInsert event of the form to perform the
SendObject?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top