AllowEdits & Enable

  • Thread starter vincentt via AccessMonster.com
  • Start date
V

vincentt via AccessMonster.com

Hi pals,

I have a form, set Allow* = false, so the users would not accidentally amend
the form.

On the other hand, I add a button "Edit" to set back the Allow* to True and
the button changed to "Read Only" ... however, it could not reverse back to
"Edit" after clicking on "Read Only", data could still amend. Code as follow:

Private Sub btn_edit_Click()
If btn_edit.Caption = "Edit" Then
btn_edit.Caption = "Read Only"
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
Else
btn_edit.Caption = "Read Only"
btn_edit.Caption = "Edit"
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
End If

End Sub

However, I tested the code with a newly created form, created a new button
used the same name, it works!!!

May anyone know what's the problem? Is it the problem of AutoForm?


On the other hand, I have tried to use 2 button, one is Edit, another is Read
Only. I want the Edit button would "Enable = false" after click it, and Read
Only will "Enable = true", however, I cannot make it. I think I must have
something wrong on the code....

Private Sub btn_edit_Click()
btn_readonly.Enable = True
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
btn_edit.Enable = False
End Sub

I am just new to VBA and keep trying, please help!

Thanks all in advance!
 
R

Rick Brandt

vincentt said:
Hi pals,

I have a form, set Allow* = false, so the users would not
accidentally amend the form.

On the other hand, I add a button "Edit" to set back the Allow* to
True and the button changed to "Read Only" ... however, it could not
reverse back to "Edit" after clicking on "Read Only", data could
still amend. Code as follow:

Private Sub btn_edit_Click()
If btn_edit.Caption = "Edit" Then
btn_edit.Caption = "Read Only"
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
Else
btn_edit.Caption = "Read Only"
btn_edit.Caption = "Edit"
Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False
End If

End Sub

However, I tested the code with a newly created form, created a new
button used the same name, it works!!!

May anyone know what's the problem? Is it the problem of AutoForm?


On the other hand, I have tried to use 2 button, one is Edit, another
is Read Only. I want the Edit button would "Enable = false" after
click it, and Read Only will "Enable = true", however, I cannot make
it. I think I must have something wrong on the code....

Private Sub btn_edit_Click()
btn_readonly.Enable = True
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True
btn_edit.Enable = False
End Sub

I am just new to VBA and keep trying, please help!

Thanks all in advance!

Was the form perhaps "Dirty" when you attempted to toggle it back? I don't
think you can set the form to disallow edits while an unsaved record is
being displayed.
 
V

vincentt via AccessMonster.com

Oh, Rick,

I found the answer!! You gave me hints, so I just have add a command to save
(requery) after click the button, and it works fine!!!

Thanks!
 
P

Pat Hartman\(MVP\)

Requery is not the way to save the current record. Use:
If Me.Dirty Then
DoCmd.RunCommand acCmdSaveRecord
End If

Saving the current record is a side effect of the requery method but you
will find that using requery when you shouldn't has undesirable side
effects.
 

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