Yes or No Prompt

G

Guest

I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
S

Scottgem (MVP)

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If
 
G

Guest

Scott,

Thank You

Where exactly should this code go?

Scottgem (MVP) said:
If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
S

Scottgem (MVP)

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

Thank You

Where exactly should this code go?

Scottgem (MVP) said:
If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
G

Guest

Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

Scottgem (MVP) said:
Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

Thank You

Where exactly should this code go?

Scottgem (MVP) said:
If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
S

Scottgem (MVP)

Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

Scottgem (MVP) said:
Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
G

Guest

Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and then
press the "Yes" button, it works as planned (prints report and closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report and
then prompts me for the missing data. I would like this to be reversed.
3. If I enter all the required data and press the "Confirm" button and then
press the "No" button, it gives me an error and pints to the "Me.Dirty =
False" code when debugging.

Any ideas, you have been a great help.

Tim

Scottgem (MVP) said:
Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

Scottgem (MVP) said:
Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
S

Scottgem (MVP)

Try it this way:

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

The Dim and error trapping should go OUTSIDE the IF.
--
HTH
Scott<>
Microsoft Access MVP 2007
Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and then
press the "Yes" button, it works as planned (prints report and closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report and
then prompts me for the missing data. I would like this to be reversed.
3. If I enter all the required data and press the "Confirm" button and then
press the "No" button, it gives me an error and pints to the "Me.Dirty =
False" code when debugging.

Any ideas, you have been a great help.

Tim

Scottgem (MVP) said:
Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

:

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
G

Guest

I have pasted your code into the "On Click" event of the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

Now the following occurs:
If I enter all the required data it prompts "Yes" or "No", If I press "Yes"
it prints a blank report, but the data is in the table. If I press "No" the
following message box appears

"The setting you entered isn't valid for this property - "OK"

If I press "OK" it returns me to the blank data entry screen and does not
save it to the table.

Scottgem (MVP) said:
Try it this way:

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

The Dim and error trapping should go OUTSIDE the IF.
--
HTH
Scott<>
Microsoft Access MVP 2007
Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and then
press the "Yes" button, it works as planned (prints report and closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report and
then prompts me for the missing data. I would like this to be reversed.
3. If I enter all the required data and press the "Confirm" button and then
press the "No" button, it gives me an error and pints to the "Me.Dirty =
False" code when debugging.

Any ideas, you have been a great help.

Tim

Scottgem (MVP) said:
Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

:

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
S

Scottgem (MVP)

Hmm, not sure why its doing that. The only thing I can suggest at this
point is to post this problem at utteraccess.com where you can attach a
copy of your database and let the helpers there (many of the same people
who help here) look at it.

--
HTH
Scott<>
Microsoft Access MVP 2007
I have pasted your code into the "On Click" event of the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

Now the following occurs:
If I enter all the required data it prompts "Yes" or "No", If I press "Yes"
it prints a blank report, but the data is in the table. If I press "No" the
following message box appears

"The setting you entered isn't valid for this property - "OK"

If I press "OK" it returns me to the blank data entry screen and does not
save it to the table.

Scottgem (MVP) said:
Try it this way:

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

The Dim and error trapping should go OUTSIDE the IF.
--
HTH
Scott<>
Microsoft Access MVP 2007
Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm" button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and then
press the "Yes" button, it works as planned (prints report and closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report and
then prompts me for the missing data. I would like this to be reversed.
3. If I enter all the required data and press the "Confirm" button and then
press the "No" button, it gives me an error and pints to the "Me.Dirty =
False" code when debugging.

Any ideas, you have been a great help.

Tim

:

Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see code
below) I want a "Yes" / "No" prompt to appear to prompt them to save or
cancel report. I want to eliminate the "Submit" and "Cancel" buttons
alltogther to minimize the buttons they have to "remember" to press.

I wanted to eliminate the "Submit" button, so can I place this code in the
"Confirm" button" (see code below for the "Confirm" button and the form
"Before Update" code)?

If so, could you detail what exactly should be placed in the "submit code"
sections of your suppled code.

Or if you have any better suggestions, that would be great also. But, at a
minimum I need to keep the "Confirm" button to ensure the required data is
entered.

:

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirm†button that
the person must press after data has been entered to check that the required
data has been into the form. For the confirm button to work each of the
required fields is tagged with an “Râ€. They then must press either a
“Submit†button to save the entered data and print a report of the data just
entered, or press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “No†prompt box
appear after the person presses a “Confirm†button, to respond to the
question “Save this Report?.†With the current process, people are
forgetting to press either the “Submit†or “Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
I

i_takeuti

Scottgem (MVP) said:
Try it this way:

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

The Dim and error trapping should go OUTSIDE the IF.
--
HTH
Scott<>
Microsoft Access MVP 2007
Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm"
button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and
then press the "Yes" button, it works as planned (prints report and
closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report
and then prompts me for the missing data. I would like this to be
reversed.
3. If I enter all the required data and press the "Confirm" button and
then press the "No" button, it gives me an error and pints to the
"Me.Dirty = False" code when debugging.

Any ideas, you have been a great help.

Tim

Scottgem (MVP) said:
Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see
code below) I want a "Yes" / "No" prompt to appear to prompt them to
save or cancel report. I want to eliminate the "Submit" and "Cancel"
buttons alltogther to minimize the buttons they have to "remember" to
press.

I wanted to eliminate the "Submit" button, so can I place this code in
the "Confirm" button" (see code below for the "Confirm" button and the
form "Before Update" code)?

If so, could you detail what exactly should be placed in the "submit
code" sections of your suppled code.

Or if you have any better suggestions, that would be great also. But,
at a minimum I need to keep the "Confirm" button to ensure the required
data is entered.

:

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirmâ€
button that the person must press after data has been entered to
check that the required data has been into the form. For the
confirm button to work each of the required fields is tagged with
an “Râ€. They then must press either a “Submit†button to save
the entered data and print a report of the data just entered, or
press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “Noâ€
prompt box appear after the person presses a “Confirm†button, to
respond to the question “Save this Report?.†With the current
process, people are forgetting to press either the “Submit†or
“Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 
G

Guest

I tried this code in the "Confirm" buttons on click event and it still prints
the report then prompts for the missing required data, then closes the form.

What I'm looking for is it to prompt for the required data (not close the
form, but be able to enter the date), prompt "YES" or "NO" to submit the
record, and print report of record if "YES" and cancel and close if "NO".

I don't know if this has anything to do with what you are tryin but in the
beginning code I have this, where I have added the second line.

Option Compare Database
Dim AllowSave As Boolean



i_takeuti said:
Scottgem (MVP) said:
Try it this way:

Private Sub VERIFY_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String

strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID

If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Else
Me.Dirty = False
DoCmd.Close
End If

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click

End Sub

The Dim and error trapping should go OUTSIDE the IF.
--
HTH
Scott<>
Microsoft Access MVP 2007
Making some progress.

This is the code that I now have on the "On Click" event of the "Confirm"
button which shows the "Yes"/"No" prompt after pressing the "Confirm"
button.

Private Sub VERIFY_BUTTON_Click()
If MsgBox("Submit this NMR?", vbYesNo) = vbYes Then
AllowSave = True
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close
Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
Else
Me.Dirty = False
DoCmd.Close
End If
End Sub

The problems I encounter now are:
1. If I enter all the required data and press the "Confirm" button and
then press the "Yes" button, it works as planned (prints report and
closes form).
2. If I do not enter all the required data (as a test) and press the
"Conform" button and then press the "Yes" button, it prints the report
and then prompts me for the missing data. I would like this to be
reversed.
3. If I enter all the required data and press the "Confirm" button and
then press the "No" button, it gives me an error and pints to the
"Me.Dirty = False" code when debugging.

Any ideas, you have been a great help.

Tim

:

Ok, there is some simple logic here. Lets analyze the code snippet I
gave you.

If MsgBox("Confirm", vbYesNo) = vbYes Then

This line uses the MsgBox function to display a message with Yes and No
buttons. It then test to see whether the response was a Yes. If it was,
it will process the code you use to submit the record.

Else

If the answer is no, it goes to the Else clause and will process
whatever cancel code you use.

Since you want to prompt to appear when you press the Confirm button,
then it should be placed in the code module behind that button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

I am new at creating code for my application, so bear with me.

What I am trying to do is once they press the "Confirm" button (see
code below) I want a "Yes" / "No" prompt to appear to prompt them to
save or cancel report. I want to eliminate the "Submit" and "Cancel"
buttons alltogther to minimize the buttons they have to "remember" to
press.

I wanted to eliminate the "Submit" button, so can I place this code in
the "Confirm" button" (see code below for the "Confirm" button and the
form "Before Update" code)?

If so, could you detail what exactly should be placed in the "submit
code" sections of your suppled code.

Or if you have any better suggestions, that would be great also. But,
at a minimum I need to keep the "Confirm" button to ensure the required
data is entered.

:

Wherever you want to. Probably in your Submit button.

--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
Scott,

Thank You

Where exactly should this code go?

:

If MsgBox("Confirm", vbYesNo) = vbYes Then
submit code
Else
cancel code
End If



--
HTH
Scott<>
Microsoft Access MVP 2007

tlynn wrote:
I currently have a data entry from only set up with a “Confirmâ€
button that the person must press after data has been entered to
check that the required data has been into the form. For the
confirm button to work each of the required fields is tagged with
an “Râ€. They then must press either a “Submit†button to save
the entered data and print a report of the data just entered, or
press the “Cancel†to delete the data an close the form.

I would like to change this process to have a “Yes†or “Noâ€
prompt box appear after the person presses a “Confirm†button, to
respond to the question “Save this Report?.†With the current
process, people are forgetting to press either the “Submit†or
“Cancel†buttons.

Any other ideas/options would also be appreciated:


The “Confirm†buttons “On Click†code is:
Private Sub VERIFY_BUTTON_Click()
AllowSave = True
Me.Dirty = False
DoCmd.Close
End Sub

The Forms “Before Update†code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
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

The “Submit†buttons “On Click†code is:
Private Sub SAVE_BUTTON_Click()
On Error GoTo Err_SAVE_BUTTON_Click
Dim strDocName As String
Dim StrWhere As String
strDocName = "Q-NMR Report"
StrWhere = "[ID]=" & Me!ID
DoCmd.OpenReport strDocName, acPrint, , StrWhere
DoCmd.Close

Exit_SAVE_BUTTON_Click:
Exit Sub
Err_SAVE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_SAVE_BUTTON_Click
End Sub

The “Cancel†buttons “On Click†code is:
Private Sub ERASE_BUTTON_Click()
On Error GoTo Err_ERASE_BUTTON_Click
If Me.Dirty Then
Me.Undo
End If
If Not Me.NewRecord Then
RunCommand acCmdDeleteRecord
End If
DoCmd.Close
Exit_ERASE_BUTTON_Click:
Exit Sub
Err_ERASE_BUTTON_Click:
MsgBox Err.DESCRIPTION
Resume Exit_ERASE_BUTTON_Click
End Sub
 

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