Data entry required, close form, print report

G

Guest

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?
 
S

strive4peace

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
*
 
G

Guest

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

strive4peace said:
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
*


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?
 
S

strive4peace

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
*


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

strive4peace said:
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
*


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?
 
G

Guest

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?

strive4peace said:
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
*


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

strive4peace said:
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?
 
S

strive4peace

Hi Tim,

since you want the form to be printed before going to another record,
set the form Cycle property to Current Record

since you need to make sure that all data is printed, you may want to
include a PrintDate that gets updated by the code behind the report --
then you can make sure everything does indeed have a PrintDate filled.

Now, how to make them print before entering more... set the form
AllowAdditions to false. have a button to make a new record -- and that
code should make sure the current record has been saved and printed.

Do you want to use the Form AfterUpdate event to print? If there is
already a PrintDate, it does not need to be done again, right? Or does
it since changes have been made?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*


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?

strive4peace said:
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
*


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?
 
G

Guest

Hi Crystal,

Thank you again for the prompt response.

The forms Cycle property is already set to Current Record. I believe I did
this so that floor personnel would only see a new record when they opened the
form. I do not want them to have access to other form data that they could
delete or revise.

As far as the PrintDate (second paragraph) I am lost as to what this code
should look like behind the report and where it should go. Could you
elaborate? I really don't need a PrintDate on the report, unless this will
get me the what I am looking for. The reports already have a Date Issued
field that is created when the record is created (hidden from the floor
person).

Currently the Allow Additions property is set to Yes, Do I set it to No or
False?

I would like to use the forms AfterUpdate event to print, but this is where
the code is to verify that the required data is entered. I was not able to
combine the code for the required data and the print report code (in original
request).

Now, if we put the print code in the AfterUpdate event, how does this work
when the person enters data into the form, but then cancels that data. Does
the report still print as a blank. This is where I was before, but at this
point I could live with a couple of blank reports a week if I cannot arrange
the code for what I am looking for.

Regards,
Tim

strive4peace said:
Hi Tim,

since you want the form to be printed before going to another record,
set the form Cycle property to Current Record

since you need to make sure that all data is printed, you may want to
include a PrintDate that gets updated by the code behind the report --
then you can make sure everything does indeed have a PrintDate filled.

Now, how to make them print before entering more... set the form
AllowAdditions to false. have a button to make a new record -- and that
code should make sure the current record has been saved and printed.

Do you want to use the Form AfterUpdate event to print? If there is
already a PrintDate, it does not need to be done again, right? Or does
it since changes have been made?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*


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?

strive4peace said:
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?
 
S

strive4peace

Hi Tim,

you're welcome

PrintDate --> I was suggesting that you add the following field to your
data table:

PrintDate, date/time

right now, you have no way to know if a record when to a report... If
you updated a PrintDate field in each record in the recordset, you would
at least have a way to verify that the record went to a report.

Do you have overall reports you print at the end of the day to ensure
that the records entered match the records printed?

"I would like to use the forms AfterUpdate event to print, but this is
where the code is to verify that the required data is entered. "

Record validation code should be on the form BeforeUpdate event -- that
happens BEFORE a record is written and you have an opportunity to CANCEL
the changes or new record. If changes are made that require the record
to be printed (again), the PrintDate can be set to null.

AfterUpdate means that the record was just written and it is time to
print...or see if it needs to be printed.

Another thing you could do is let the data entry people have at it and
then every hour or so, print all the records with no PrintDate ...
assuming it will be updated by the report code.

"how does this work when the person enters data into the form, but then
cancels that data..."

if the data is cancelled an no record is created or changed, there is no
AfterUpdate event...

If your report is filtered for records with a Null PrintDate... in the
code behind the report -- like on the Close event... you can update all
records with no PrintDate to the current date and time.

This is assuming that you have the report filtered for records with a
PrintDate Is Null

'~~~~~~~~~~~~~~~~
dim strSQL as string
strSQL = "UPDATE tablename " _
& " SET PrintDate=#" & now() & "# " _
& " WHERE PrintDate Is Null"
currentdb.execute strSQL

To me, this is the "safest" way ... if a record, for some reason doesn't
get printed when it is entered, it will be printed in the next batch.

"Currently the Allow Additions property is set to Yes, Do I set it to No
or False?"

if you want to send reports before another record is added, you could
make users go to a new record by clicking a button -- then, you can
print report(s) and add a record with code (Me.AddNew)

and the user can fill it out ;)


Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*


Hi Crystal,

Thank you again for the prompt response.

The forms Cycle property is already set to Current Record. I believe I did
this so that floor personnel would only see a new record when they opened the
form. I do not want them to have access to other form data that they could
delete or revise.

As far as the PrintDate (second paragraph) I am lost as to what this code
should look like behind the report and where it should go. Could you
elaborate? I really don't need a PrintDate on the report, unless this will
get me the what I am looking for. The reports already have a Date Issued
field that is created when the record is created (hidden from the floor
person).

Currently the Allow Additions property is set to Yes, Do I set it to No or
False?

I would like to use the forms AfterUpdate event to print, but this is where
the code is to verify that the required data is entered. I was not able to
combine the code for the required data and the print report code (in original
request).

Now, if we put the print code in the AfterUpdate event, how does this work
when the person enters data into the form, but then cancels that data. Does
the report still print as a blank. This is where I was before, but at this
point I could live with a couple of blank reports a week if I cannot arrange
the code for what I am looking for.

Regards,
Tim

strive4peace said:
Hi Tim,

since you want the form to be printed before going to another record,
set the form Cycle property to Current Record

since you need to make sure that all data is printed, you may want to
include a PrintDate that gets updated by the code behind the report --
then you can make sure everything does indeed have a PrintDate filled.

Now, how to make them print before entering more... set the form
AllowAdditions to false. have a button to make a new record -- and that
code should make sure the current record has been saved and printed.

Do you want to use the Form AfterUpdate event to print? If there is
already a PrintDate, it does not need to be done again, right? Or does
it since changes have been made?

Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*


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?
 

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

Top