Hi Crystal,
You are correct in the statement about the codes location.
What I am trying to do with this confirm button is to make it an automatic
process where the user on the floor only has to press one button to confirm
the data, print a report and close the form. Along with the other option of
clearing the current record and/or deleting the current record. Only 2
button total for the floor person to use.
I have tried seperate "Confirm" and "Print" buttons but the operators had
ways of getting around those and/or not pressing the print button. It is
imperative that once data is entered from a floor person a hard-copy record
is printed.
Any other ideas?
:
Hi Tim,
this statement indicates that you have code on the AfterUpdate event of
a control...
"the report would still try and print on the after-update function and I
would an error relating to trying to print a report with no data"
and then here, it looks like you have code on the form Current event...
"I am able to close the form and print the report (see code below) using
a current command button"
right now, you should have code on the form BeforeUpdate and the click
event of a button. If you have code on the Current event or other events
(related to this), then comment it out.
you said:
"I am looking for a "Confirm" button to test required data, close the
form and print a report (or print a report/close the form), and a
"Delete" button to delete any data entered in error or that was
incorrect and not print a report."
You already have your data validation in the form BeforeUpdate event,
which is triggered when you try to save a record (me.dirty=false)
Did you try the code I gave you on the Click event of a button It does
everything you want except close the form
Docmd.Close acForm, Me.Name
And when you close, it is better to explicity state what you want to
close ... especially since the code has just opened a report and that
will be the active object...
.... now, if the user just closes the form without clicking the button,
or they go to the next record without clicking the button, we can help
you with other tracking variables that can launch code you can add once
the basic functionality is there...
Warm Regards,
Crystal
*
have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
tlynn wrote:
Thank you for your prompt response. and you are correct about the report
button.
But in my application what I am trying to do is the following.
I have personnel out on the floor entering data into a form. Once they are
done entering data they will press a "Confirm" button which will test to make
sure the data that is requuired is entered (via the on_click funrtion of this
button and the previous code). If all the required data is not entered, it
will prompt them to enter the required data. But from here I would like the
same button "Confirm" button to save the record, close the form and then
print a report to my printer in the office. I need a hard-copy of the data
that was entered for other purposes.
I had two seperate buttons that would accomplish this task, a "Save" button
would check that the required data was entered, then a "Main Menu" button
that would get you back to the main menu, but would also close the form and
print a report on the after_update function of the form. The problem with
this was that if the person wanted to not enter data and/or close the form
without entereing data (via "Delete" button), the report would still try and
print on the after-update function and I would an error relating to trying to
print a report with no data.
So in a nut shell, I am looking for a "Conform" button to test required
data, close the form and print a report (or print a report/close the form),
and a "Delete" button to delete any data entered in error or that was
incorrect and not print a report.
I hope this better explains my situation.
Thanks in advance for your help - Tim
:
Hi Lynn,
Why are you closing the form? Why not just have a REPORT button on the
form?
You should save the current record before opening the report. How about
trying something like this:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if me.dirty then me.dirty = false
'if the record is still dirty then
'validation didn't pass
'THIS IS NOT TESTED
if me.dirty then exit sub
Dim strDocName As String
Dim StrWhere As String
strDocName = "M-Maintenance Request"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acprint, , StrWhere
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warm Regards,
Crystal
*
have an awesome day
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
tlynn wrote:
I would like to enter data into my form and once entered check to make sure
the data is in the required fields, then I would like to close this form and
print a report.
I am checking that the required data is entered by using the following code
on the form "Before_Update" which works great.
Private Sub Form_BeforeUpdate()
Dim ctl As Control
For Each ctl In Me.Controls
If ctl.Tag = "R" Then
If Nz(ctl.Value) = 0 Then
MsgBox "The " & ctl.Name & " field is required. Please enter
a value."
ctl.SetFocus
Exit For
End If
End If
Next ctl
If AllowSave Then
AllowSave = False
Else
Me.Undo
Cancel = True
End If
End Sub
But now I want to take it a step further and maybe by using a command button
(Confirm) to check for the required data but also close the form and print a
report.
I am able to close the form and print the report (see code below) using a
current command button but I am trying to minimuze the number of buttons the
user has to use.
Dim strDocName As String
Dim StrWhere As String
strDocName = "M-Maintenance Request"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acprint, , StrWhere
Docmd.Close
Any ideas for the code?