To make your coding easier try using my generic locking code at:
http://www.datastrat.com/Code/LockIt.txt
Then set the form to Dirty, which will save it before running the code. So:
If Me.Dirty = True Then Me.Dirty = False
will force a save of a dirty record or:
DoCmd.RunCommand acCmdSaveRecord
will force a save under any condition that won't violate validation.
--
Arvin Meyer, MCP, MVPhttp://
www.datastrat.comhttp://www.mvps.org/accesshttp://www.accessmvp.com
Hi Arvin,
Thanks for your reply! The checkbox I was referring to was not the one
in the message box, but the checkbox on the form where one marks the
inspection as passed. I changed it to "True" as Sean suggested (I
missed that earlier) and now I am getting the message box! And
clicking OK does kick off the sql string to do the update. I had to
change my code a little bit (Yes for the locked checkbox was in quotes
and it didn't like that), but it is updating fine.
I wanted the subform to lock after the locked property is updated, so
I added the code to disable the controls.
Here's what the final code looks like:
======================================================
Private Sub Form_BeforeUpdate(Cancel As Integer)
Dim stUpdate As String
stUpdate = "UPDATE tblPart SET tblPart.Locked = Yes WHERE
(((tblPart.Part_AN)=[Forms]![frmPart]![frmPartTasks].[Form]!
[Part_AN]));"
If Me.Sequence = "Final" And Me.Pass = True Then
Dim x
x = MsgBox("Marking the Final Inspection as Passed will" & vbCrLf &
"lock this part to further edits. Do you want to continue?", vbYesNo +
vbQuestion)
If x = vbYes Then
DoCmd.RunSQL stUpdate
Me.Date.Enabled = False
Me.Task.Enabled = False
Me.cboSequence.Enabled = False
Me.By.Enabled = False
Me.Pass.Enabled = False
Me.ToLoc.Enabled = False
Me.Notes.Enabled = False
Else
Cancel = True
Me.Undo
End If
End If
End Sub
====================================================
It works beautifully, the Part Tasks subform is locked and all is good
with the world. There is just one little "bug" I would like to fix if
you have an idea on this. If I click "No" and go back to the record
(this gives the operator the chance to change to another inspection
type or uncheck the inspection as passed), it seems like once Access
has executed the code on that record, it will allow it to save without
running the update query. The Cancel and Undo lines up there in the
Else statement leave Passed checked and return to the cursor to the
top record in the subform. Even if I tab through the record with
"Final" selected and "Passed" checked, it doesn't run the code again.
What would be the best way to approach this? Thank you for your
responses. You've helped me so much! I've been working on this off and
on for at least a couple of months!
Regards,
Ruth
There is no check box in a MsgBox function.
Also, the syntax would be Not IsNull(Me.txtControlName)
If Len(Me.txtControlName & vbNullString) > 0 Then
which covers both conditions (Null and empty string)