"Edit" Command Button

M

mcjanes

I have a form containing personal information about students. I have
the form's properties set to "no edits", to prevent accidental edits.

I would like to have a Command Button labeled "Edit Student
Information", which allows me to edit all of the information about the
current record in the form. How can I do this? Also, it'd be neat to
have the Command Button change its label to "Save Changes" while in
"allow edit" mode...when I click the "Save" button, obviously the edits
will be saved and it will return to "no edit" mode (along with the
command button changing back to "Edit Student Information"..

I know this is possible, because I downloaded a "demo" database where
this exact system occurs.

I'm guessing it has to be done in MVB, with which I have no experience,
so feel free to "dumb it down".

Thanks!
 
J

Jeff L

You would need something like this in your On Click event of your
command button.

If Me.MyButton.Caption = "Edit Record" Then
Me.AllowEdits = True
Me.MyButton.Caption = "Save Record"
Else
Me.AllowEdits = False
Me.MyButton.Caption = "Edit Record"
End If

You may need a bit more but I don't know how you are accessing your
data on your form. If it is connected to a table or query, you
wouldn't necessarily need to run a save procedure for your changes.
Anyway, that is how you would change the AllowEdits setting as well as
the Caption for the button.

Hope that helps!
 
J

Joseph Meehan

I have a form containing personal information about students. I have
the form's properties set to "no edits", to prevent accidental edits.

I would like to have a Command Button labeled "Edit Student
Information", which allows me to edit all of the information about the
current record in the form. How can I do this? Also, it'd be neat to
have the Command Button change its label to "Save Changes" while in
"allow edit" mode...when I click the "Save" button, obviously the
edits will be saved and it will return to "no edit" mode (along with
the command button changing back to "Edit Student Information"..

I know this is possible, because I downloaded a "demo" database where
this exact system occurs.

I'm guessing it has to be done in MVB, with which I have no
experience, so feel free to "dumb it down".

Thanks!

One easy, but messy, way is to create a series of forms. Copy the
original and make changes as needed.

The button on one will take the user to the second, the button will look
the same on the second, except the text may be different, but it will take
them back to the first. You can even have more than two forms depending on
the needs.
 
A

Allen Browne

Jeff's solution is simple and effective. But if your form has unbound
controls (e.g. to navigate or filter the form), you won't be able to use
them either. If that's an issue, the alternative is to loop through the
controls on the form, and set the Locked property of the bound controls.
There's code to do that in this link:
Locking bound controls on a form and subforms
at:
http://allenbrowne.com/ser-56.html

A slight enhancement to Jeff's code. Access won't actually apply the
AllowEdits while the record is dirty, so it would be good to explicitly save
the record:

If Me.MyButton.Caption = "Edit Record" Then
Me.AllowEdits = True
Me.MyButton.Caption = "Save Record"
Else
If Me.Dirty Then Me.Dirty = False
Me.AllowEdits = False
Me.MyButton.Caption = "Edit Record"
End If
 
M

mcjanes

Wow, thanks guys! The link Allen Browne posted worked perfectly! I've
run into a problem, though. I still need to have an "Add Student"
button. How can I make this unlock the form for editing as well?
 
A

Allen Browne

If you are using the LockBoundControls() code from:
http://allenbrowne.com/ser-56.html
the Click event procedure for your button would be something like this:

Private Sub AddStudent_Click()
If Me.Dirty Then
Me.Dirty = False
End If
If Not Me.NewRecord Then
RunCommand acCmdRecordsGotoNew
End If
Call LockBoundControls(Me, False)
End Sub
 
M

mcjanes

Once again, thank you very much!

One more thing...it says to add any subforms you don't want locked to
the exception list....where exactly do I put that inside the module?
The subform's name is tbl_CheckOut_subform
 
A

Allen Browne

No need to change the module. Just pass their names, in quotes, separated by
commas, as many as you need, e.g.:
Call LockBoundControls(Me, False, "Sub1", "MyOtherSubform",
"AndThisOneToo", "Combo1")

The code just doesn't touch any of the controls named in the exception list.
If they were locked before, they stay locked. If they were unlocked when you
saved the form, they stay unlocked.
 
M

mcjanes

Sorry, but I'm still not getting it....if I don't put this code in the
module, then where does it go??
 
A

Allen Browne

I wasn't clear.

Don't change anything inside the LinkBoundControls() function.
Do change the code that calls the function.
 
M

mcjanes

I feel like an idiot....I'm still not getting it! :p

when you say "DO change the code that calls the function", do you mean
the code =LockBoundControls([Form],True) in the form's properties under
"On Load"?

If so, I know I need to add
Call LockBoundControls(Me, bLock, "tbl_CheckOut_subform") to this line
under "On Load". How, exactly do I put that line in? do I just put a
comma after =LockBoundControls...

remember, I have EXTREMELY little knowledge of how this type of coding
works...

thanks again
 
A

Allen Browne

You can call it 2 ways.

Either set the property to:
=LockBoundControls([Form], False, "Sub1", "Sub2")

Or, set the property to:
[Event Procedure]
Then click the Build button (...) beside this.
Access opens the code window.
In the code window, between the "Private Sub..." and "End Sub" lines, enter:
Call LockBoundControls(Me, False, "Sub1", "Sub2")

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

I feel like an idiot....I'm still not getting it! :p

when you say "DO change the code that calls the function", do you mean
the code =LockBoundControls([Form],True) in the form's properties under
"On Load"?

If so, I know I need to add
Call LockBoundControls(Me, bLock, "tbl_CheckOut_subform") to this line
under "On Load". How, exactly do I put that line in? do I just put a
comma after =LockBoundControls...

remember, I have EXTREMELY little knowledge of how this type of coding
works...

thanks again

Allen said:
I wasn't clear.

Don't change anything inside the LinkBoundControls() function.
Do change the code that calls the function.
 

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

Similar Threads

Command Button 2
Edit Records 2
Edit Record Command 2
Command Button 2
List Items Edit Form want to open to blank entry 6
FORM Please HELP 2
Hyperlink 3
keep button press from editing form 6

Top