MSGBOX

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,
I would like to implement a POP Up MsgBox on my form when I select a Command
Button called "Print"

It should show 3 lines of text, 2 Buttons, a title and an Icon

i.e.

----------------------------
On Clicking the print button...

You are about to print this record
Doing so will also lock the record for any further editing.
Are you sure you want to do that?

vbOk vbCancel

Exclamation mark Icon
-----------------------------

vbOk button should print a report called rptSalesReceipt
vbCancel should cancel the msgbox and printing events.

Any help Please

Regards

John
 
For the code to save and print the record, see:
Print the record in the form
at:
http://allenbrowne.com/casu-15.html

To lock your form so that no edits are allowed after a record has been
entered, set the form's AllowEdits property to No. You probably want to set
AllowDeletions to No as well.
 
Thanks for the reply Allen,

Most helpful but entirely what I was looking for.

The reason for the vbOK and vbCancel buttons was to allow a user to cancel
the print and the locking of the form if they clicked the wrong button by
mistake.

Regards

John
 
So you don't want the record locked as soon as it is saved, but as soon as
it is printed.

In that case, you will need to have a yes/no field in your table to record
which records are now locked, and set this field to True when printed so the
record is always locked after that. This example assumes this field is named
IsLocked.

Private Sub cmdPrint_Click()
If Not Me.IsLocked.Value Then
If MsgBox("Save, print and lock?", vbOkCancel, "Confirm") = vbOk
Then
Me.IsLocked.Value = True 'Set as locked.
Me.Dirty = False 'Save the changes.
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewNormal, , strWhere
End If
End If
End Sub

You will then need to use the Current event of the form to ensure each
record is locked when loaded into the form:

Private Sub Form_Current()
Dim bLock As Boolean
bLock = Nz(Me.IsLocked, False)
If Me.AllowEdits = bLock Then
Me.AllowEdits = Not bLock
Me.AllowDeletions = Not bLock
End If
End Sub
 
Dim strMessage As String

strMessage = "You are about to print " & _
"this record" & vbCrLf & _
"Doing so will also lock the record for " & _
"any further editing." & vbCrLf & _
"Are you sure you want to do that?"

If MsgBox(strMessage, vbOkCancel + _
vbExclamation) = vbOk Then
DoCmd.OpenReport "MyReport"
End If
 
Back
Top