Can I use a comand button to change the form properties?

  • Thread starter Thread starter Tom K via AccessMonster.com
  • Start date Start date
T

Tom K via AccessMonster.com

Hi
I would like to use a command button to change my forms properties. The forms
AllowEdits, AllowAdditions, and AllowDeletetions is normally set to No. I
would like to have a button to set them to Yes. Can this be done with the
setvalue action in a macro.

Thanks,

Tom
 
On the Onclick event of the button, you can write the code

Me.AllowDeletions = True
Me.AllowEdits = True
Me.AllowAdditions = True
 
Thanks,
Can I do this with a macro?
Tom said:
On the Onclick event of the button, you can write the code

Me.AllowDeletions = True
Me.AllowEdits = True
Me.AllowAdditions = True
Hi
I would like to use a command button to change my forms properties. The forms
[quoted text clipped - 5 lines]
 
Why would you want to go through the extra steps of doing it in a macro?
Just use the code. It's easier and cleaner.

--
Rick B



Tom K via AccessMonster.com said:
Thanks,
Can I do this with a macro?
Tom said:
On the Onclick event of the button, you can write the code

Me.AllowDeletions = True
Me.AllowEdits = True
Me.AllowAdditions = True
Hi
I would like to use a command button to change my forms properties. The
forms
[quoted text clipped - 5 lines]
 
What code could I use with this to allow me to enter a new record? Like the
macro action Add New Record.
Tom
 
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.

One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.

Thanks,
Darrell
Thanks,
Can I do this with a macro?
Tom said:
On the Onclick event of the button, you can write the code

Me.AllowDeletions = True
Me.AllowEdits = True
Me.AllowAdditions = True

Hi
I would like to use a command button to change my forms properties. The forms

[quoted text clipped - 5 lines]
 
I would like to make it harder for users to edit records, but not impossible.
Using a New Record Form or a Edit Records Form works but it seems like there
should be a better way. Using the AddRecord button that is on the form or
leaving a form that can be edited just seems like it would be to easy to
delete or screw up data by accident.

What is the best way to handle forms and not make it to easy to screw up the
data?

Tom

Darrell said:
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.

One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.

Thanks,
Darrell
Thanks,
Can I do this with a macro?
[quoted text clipped - 12 lines]
 
I have just done this myself for the first time and got it working.. hot off
the press!

I think an "Add Record" button is safe because the users will se quite
clearly new blank fields appearing on the form so will know they are about to
input new records. You can create another button, "CANCEL," and have it
appear on the screen after the Add Record button is pressed to make things
even clearer and failsafe (we'll see....!!!)
do this by including this in the Add Record button's onClick event:

Me.YourButtonName.Visible = true

To stop users from causing an error by potentially clicking the "Add New
Record" button again whilst already in Add Mode, position the new button on
top of the Add New button in design view, then set its visible property to no
in properties window of design view.
this new button might be labelled "Cancel Add New Record (without saving)."
Set its onClick value to the following in VBA:

Private Sub YourButtonName_Click()
If Me.Dirty Then Me.Undo
DoCmd.GoToRecord , , acPrevious
Me.[YourField].SetFocus
Me.YourButtonName.Visible = False

When the user clicks this button, the "new" record will not be deleted and
the form will go back to showing a previous record. If any changes have been
made to the blank fields in the form, they will not be saved - so a new
record will not be created. The Cancel button disappears to show the add new
record button again.

Note that this works in a single form - I'm not sure if it would work in a
continuous form (although it might....) but the potential problem is that it
might undo any changes to other records in the subform (not sure about
this...)

** Does anyone know how to get the form to display the record it was showing
before the "Add new record" button was pressed (ie before the form was opened
in add mode....?) This VBA doesn't seem to work (instead it displays the
first record in the table for some reason.....) Should this be working?
Maybe I've got a form resfresh happening which is stopping this....?? Let me
know if you do!**


DoCmd.GoToRecord , , acPrevious

Tom K via AccessMonster.com said:
I would like to make it harder for users to edit records, but not impossible.
Using a New Record Form or a Edit Records Form works but it seems like there
should be a better way. Using the AddRecord button that is on the form or
leaving a form that can be edited just seems like it would be to easy to
delete or screw up data by accident.

What is the best way to handle forms and not make it to easy to screw up the
data?

Tom

Darrell said:
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.

One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.

Thanks,
Darrell
Thanks,
Can I do this with a macro?
[quoted text clipped - 12 lines]
 
PS Echoing Darrell's post...
Any info on how to grey out (or make transparnet) the back colour of textbox
fields when in "view only" mode (ie edits/deletions/additions not allowed)
and then make them white when in edit or add mode would be welcome. Is there
a quick way to do this?

Thanks

Rich
Rich1234 said:
I have just done this myself for the first time and got it working.. hot off
the press!

I think an "Add Record" button is safe because the users will se quite
clearly new blank fields appearing on the form so will know they are about to
input new records. You can create another button, "CANCEL," and have it
appear on the screen after the Add Record button is pressed to make things
even clearer and failsafe (we'll see....!!!)
do this by including this in the Add Record button's onClick event:

Me.YourButtonName.Visible = true

To stop users from causing an error by potentially clicking the "Add New
Record" button again whilst already in Add Mode, position the new button on
top of the Add New button in design view, then set its visible property to no
in properties window of design view.
this new button might be labelled "Cancel Add New Record (without saving)."
Set its onClick value to the following in VBA:

Private Sub YourButtonName_Click()
If Me.Dirty Then Me.Undo
DoCmd.GoToRecord , , acPrevious
Me.[YourField].SetFocus
Me.YourButtonName.Visible = False

When the user clicks this button, the "new" record will not be deleted and
the form will go back to showing a previous record. If any changes have been
made to the blank fields in the form, they will not be saved - so a new
record will not be created. The Cancel button disappears to show the add new
record button again.

Note that this works in a single form - I'm not sure if it would work in a
continuous form (although it might....) but the potential problem is that it
might undo any changes to other records in the subform (not sure about
this...)

** Does anyone know how to get the form to display the record it was showing
before the "Add new record" button was pressed (ie before the form was opened
in add mode....?) This VBA doesn't seem to work (instead it displays the
first record in the table for some reason.....) Should this be working?
Maybe I've got a form resfresh happening which is stopping this....?? Let me
know if you do!**


DoCmd.GoToRecord , , acPrevious

Tom K via AccessMonster.com said:
I would like to make it harder for users to edit records, but not impossible.
Using a New Record Form or a Edit Records Form works but it seems like there
should be a better way. Using the AddRecord button that is on the form or
leaving a form that can be edited just seems like it would be to easy to
delete or screw up data by accident.

What is the best way to handle forms and not make it to easy to screw up the
data?

Tom

Darrell said:
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.

One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.

Thanks,
Darrell

Thanks,
Can I do this with a macro?
[quoted text clipped - 12 lines]

Tom
 
NB
Form is now showing correct (previous) record when cancel add new rec button
is pressed. Not sure why I had problems before. I did remove a refresh
earlier - not sure if this had anything to do with it. Anyway, it works

Rich1234 said:
I have just done this myself for the first time and got it working.. hot off
the press!

I think an "Add Record" button is safe because the users will se quite
clearly new blank fields appearing on the form so will know they are about to
input new records. You can create another button, "CANCEL," and have it
appear on the screen after the Add Record button is pressed to make things
even clearer and failsafe (we'll see....!!!)
do this by including this in the Add Record button's onClick event:

Me.YourButtonName.Visible = true

To stop users from causing an error by potentially clicking the "Add New
Record" button again whilst already in Add Mode, position the new button on
top of the Add New button in design view, then set its visible property to no
in properties window of design view.
this new button might be labelled "Cancel Add New Record (without saving)."
Set its onClick value to the following in VBA:

Private Sub YourButtonName_Click()
If Me.Dirty Then Me.Undo
DoCmd.GoToRecord , , acPrevious
Me.[YourField].SetFocus
Me.YourButtonName.Visible = False

When the user clicks this button, the "new" record will not be deleted and
the form will go back to showing a previous record. If any changes have been
made to the blank fields in the form, they will not be saved - so a new
record will not be created. The Cancel button disappears to show the add new
record button again.

Note that this works in a single form - I'm not sure if it would work in a
continuous form (although it might....) but the potential problem is that it
might undo any changes to other records in the subform (not sure about
this...)

** Does anyone know how to get the form to display the record it was showing
before the "Add new record" button was pressed (ie before the form was opened
in add mode....?) This VBA doesn't seem to work (instead it displays the
first record in the table for some reason.....) Should this be working?
Maybe I've got a form resfresh happening which is stopping this....?? Let me
know if you do!**


DoCmd.GoToRecord , , acPrevious

Tom K via AccessMonster.com said:
I would like to make it harder for users to edit records, but not impossible.
Using a New Record Form or a Edit Records Form works but it seems like there
should be a better way. Using the AddRecord button that is on the form or
leaving a form that can be edited just seems like it would be to easy to
delete or screw up data by accident.

What is the best way to handle forms and not make it to easy to screw up the
data?

Tom

Darrell said:
Very nice to have that! I have always wanted to find a way to do that.
How simple and efficient. I always end up making 2 identical forms - 1
with allow edits, 1 without...or I have to use 2 Switchboard commands -
1 to open a form in edit mode, 1 to open the form in add mode.

One quick question...would there be an easy way to open a form and have
all the fields grayed out initially (I guess it's really just changing
the back color of the fields) and when they click on the "EDIT" button,
it will "ungray" them - just to show a quick visual to the user whether
they are in "Edit Mode" or not. I guess it would need to be some
additional code associated with the same button.

Thanks,
Darrell

Thanks,
Can I do this with a macro?
[quoted text clipped - 12 lines]

Tom
 
Can that be accomplished with a check Box or option button that will
automatically reset to false when the record is changed?
 
Back
Top