Lock a record on Open

K

Karen

I have a form which is opened based on a choice in a combobox on another
form.

On the first form, a person is chosen and a form with that person's record
is opened with

DoCmd.OpenForm "PersonTab", acNormal, , _
"[ContactID]=" & intContactID, acFormReadOnly, , "Old"

I want the record to open in read-only mode. Also on the form's OnLoad I
have
If Me.OpenArgs = "Old" Then
lblStatus.Caption = "Record Locked - Click to Open"
lblStatus.BackColor = 255
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
ElseIf Me.OpenArgs = "Notes" Then
TabCtl0.Pages(1).SetFocus
Me.AllowEdits = True
Me.AllowDeletions=True
Me.AllowAdditions=True
Me.Details.Form.AllowAdditions = False
Me.Details.Form.AllowEdits = False
Me.Details.Form.AllowDeletions = False

Else
lblStatus.Caption = "Record Open - Click to Lock"
lblStatus.BackColor = 8421376
Me.AllowEdits = True
Me.Details.Form.AllowAdditions = True
Me.Details.Form.AllowEdits = True
Me.Details.Form.AllowDeletions = True
Me.NotesPerson.Form.AllowAdditions = True
Me.NotesPerson.Form.AllowEdits = True
Me.NotesPerson.Form.AllowDeletions = True
End If

No matter what I do, the form opens with record but it can be edited. How
do I lock a record on opening.

I've set a watch to break when Me.AllowEdits changes and I don't see any
problems, it is as though the FormOpen from the original form and the
FormLoaded conditions on the current form have no effect.
 
M

Marshall Barton

Karen said:
I have a form which is opened based on a choice in a combobox on another
form.

On the first form, a person is chosen and a form with that person's record
is opened with

DoCmd.OpenForm "PersonTab", acNormal, , _
"[ContactID]=" & intContactID, acFormReadOnly, , "Old"

I want the record to open in read-only mode. Also on the form's OnLoad I
have
If Me.OpenArgs = "Old" Then
lblStatus.Caption = "Record Locked - Click to Open"
lblStatus.BackColor = 255
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
ElseIf Me.OpenArgs = "Notes" Then
TabCtl0.Pages(1).SetFocus
Me.AllowEdits = True
Me.AllowDeletions=True
Me.AllowAdditions=True
Me.Details.Form.AllowAdditions = False
Me.Details.Form.AllowEdits = False
Me.Details.Form.AllowDeletions = False

Else
lblStatus.Caption = "Record Open - Click to Lock"
lblStatus.BackColor = 8421376
Me.AllowEdits = True
Me.Details.Form.AllowAdditions = True
Me.Details.Form.AllowEdits = True
Me.Details.Form.AllowDeletions = True
Me.NotesPerson.Form.AllowAdditions = True
Me.NotesPerson.Form.AllowEdits = True
Me.NotesPerson.Form.AllowDeletions = True
End If

No matter what I do, the form opens with record but it can be edited. How
do I lock a record on opening.

I've set a watch to break when Me.AllowEdits changes and I don't see any
problems, it is as though the FormOpen from the original form and the
FormLoaded conditions on the current form have no effect.


The only difference I see in what you've posted to similar
code I use is that I've used the Current event instead of
the Load event, but I don't think that should matter.

The only thing I can think of is that somehow or other you
managed to dirty the record and, since it's already being
edited, AllowEdits can not take effect.
 
K

Karen

Marshall,

Working on that theory, I added me.dirty=False; works like a charm :)

--
Karen

Marshall Barton said:
Karen said:
I have a form which is opened based on a choice in a combobox on another
form.

On the first form, a person is chosen and a form with that person's record
is opened with

DoCmd.OpenForm "PersonTab", acNormal, , _
"[ContactID]=" & intContactID, acFormReadOnly, , "Old"

I want the record to open in read-only mode. Also on the form's OnLoad I
have
If Me.OpenArgs = "Old" Then
lblStatus.Caption = "Record Locked - Click to Open"
lblStatus.BackColor = 255
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
ElseIf Me.OpenArgs = "Notes" Then
TabCtl0.Pages(1).SetFocus
Me.AllowEdits = True
Me.AllowDeletions=True
Me.AllowAdditions=True
Me.Details.Form.AllowAdditions = False
Me.Details.Form.AllowEdits = False
Me.Details.Form.AllowDeletions = False

Else
lblStatus.Caption = "Record Open - Click to Lock"
lblStatus.BackColor = 8421376
Me.AllowEdits = True
Me.Details.Form.AllowAdditions = True
Me.Details.Form.AllowEdits = True
Me.Details.Form.AllowDeletions = True
Me.NotesPerson.Form.AllowAdditions = True
Me.NotesPerson.Form.AllowEdits = True
Me.NotesPerson.Form.AllowDeletions = True
End If

No matter what I do, the form opens with record but it can be edited. How
do I lock a record on opening.

I've set a watch to break when Me.AllowEdits changes and I don't see any
problems, it is as though the FormOpen from the original form and the
FormLoaded conditions on the current form have no effect.


The only difference I see in what you've posted to similar
code I use is that I've used the Current event instead of
the Load event, but I don't think that should matter.

The only thing I can think of is that somehow or other you
managed to dirty the record and, since it's already being
edited, AllowEdits can not take effect.
 
M

Marshall Barton

Karen said:
Working on that theory, I added me.dirty=False; works like a charm :)


Well yeah, BUT ...

If that worked, then it confirms that you did dirty the
record. Then question then becomes, WHY? You really do not
want ot be saving changes to the record unintentially.
 
K

Karen

In the OnCurrent event I was using two functions to build a fullname and a
searchname and assign those as the values of two hidden text boxes. I guess
I could change it so those ran after the name textboxes were updated which
wouldn't happen until I allowed an edit. I'll have to experiment with that
a little later today and will post if the problems are solved.
 
R

Rod Scoullar

Karen,

OpenArgs is accessible from the Form_Open event not the Form_OnLoad event.

I spent hours trying to get it to work before I figured that out.

Rod Scoullar.
 
M

Marshall Barton

Rod said:
OpenArgs is accessible from the Form_Open event not the Form_OnLoad event.

I spent hours trying to get it to work before I figured that out.

Not so Rod. The OpenArgs property is available the entire
time the form is open. Either you have run into a bug I've
never heard of, or you have something else going on that led
you to that conclusion.

Either way, it might be worthwhile digging deeper into what
was happening.
 
K

Karen

Rod,

Marshall is right, I had set breakpoints and the OpenArgs is available as
long as the form is open. The lesson I learned, however, was that OpenArgs
had to be a string. It is very clear in the documentation, I just kept
skipping over that detail. In the few places where I really needed to pass
a number, like an index, I just use Val(Me.OpenArgs).
 
R

Rod Scoullar

Marsh,

You are obviously right, I even checked the order of events for forms and
since the open event occurs before the load event the openargs must be
available.

Thanks for the correction.

Rod
 
K

Karen

Marshall,

Long time getting back to this but I moved my fullname routine to the
AfterUpdate events of some textboxes and my problem has disappeared. Thank
you so much for the assistance.


--
Karen
Karen said:
In the OnCurrent event I was using two functions to build a fullname and a
searchname and assign those as the values of two hidden text boxes. I guess
I could change it so those ran after the name textboxes were updated which
wouldn't happen until I allowed an edit. I'll have to experiment with that
a little later today and will post if the problems are solved.
 
M

Marshall Barton

Karen said:
Marshall,

Long time getting back to this but I moved my fullname routine to the
AfterUpdate events of some textboxes and my problem has disappeared. Thank
you so much for the assistance.


Ahh, I fell much better now ;-)

The AfterUpdate event sounds like it was the right approach
all along. I'm glad you've got it all sorted now.
 

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