SubForm Editing Blues

Richie2837

Registered User.
Local time
Today, 15:26
Joined
Jan 30, 2007
Messages
88
Hi Everyone,

New to this forum and only recently self-taught in access database writing (out of necessity to save money for the charity I work for), so please excuse the basic nature of my question!

I have what is basically a glorified contacts database to store all information regarding our clients. On the form, I have set up a sub form to record all contact events made with the clients.

As the database is shared, I have had to set the editing of it to locked when it is opened, then added a command button to allow users to edit the records when they need to. However, on clicking the edit command button, the contact event sub-form remains locked. How can I get the sub-form to become editable when the edit command button is clicked?

Thanks guys.
 
What is the code you are using behind the cmdButton?

I would think something like: Me.AllowEdits = True should work.

HTH. If not let us know and we will go further,
Shane

Richie2837 said:
Hi Everyone,

New to this forum and only recently self-taught in access database writing (out of necessity to save money for the charity I work for), so please excuse the basic nature of my question!

I have what is basically a glorified contacts database to store all information regarding our clients. On the form, I have set up a sub form to record all contact events made with the clients.

As the database is shared, I have had to set the editing of it to locked when it is opened, then added a command button to allow users to edit the records when they need to. However, on clicking the edit command button, the contact event sub-form remains locked. How can I get the sub-form to become editable when the edit command button is clicked?

Thanks guys.
 
If the edit button is on the subform, then ShaneMan's suggestion will work:
Code:
Me.AllowEdits = True
Unless you have locked each individual control and if so then you would have to iterate through them to unlock each.

If the edit button is on the main form, but you want to unlock the subform, the syntax would be:
Code:
Forms!YourMainFormNameHere[B].Form.[/B]YourSubFormContainerNameOnMainFormHere.AllowEdits = True
You need the .Form. part explicitly as well when dealing with subforms.

You can only use the ME keyword if your code is on the current form in question.
 
OK.

The code I'm using (again I've cribbed this straight from someone else as I really haven't a clue here...) is:

Private Sub cmdEdit_Click()
If Me.AllowEdits And Me.Dirty Then
Me.Dirty = False ' save record
End If


Me.AllowEdits = Not Me.AllowEdits ' toggle setting
' change the button's caption
cmdEdit.Caption = IIf(Me.AllowEdits, "Restrict Edits", "Edit Record")

End Sub

' always start with no editing allowed as each record is visited
Private Sub Form_Current()
Me.AllowEdits = False
cmdEdit.Caption = "Edit Record"
End Sub

Rich
 
And as I said, if Private Sub Form_Current() and Private Sub cmdEdit_Click()
are on the main form but you want to set the subform's allow edits properties, then you have to use the syntax shown by me
Code:
Forms!YourMainFormNameHere.Form.YourSubFormContainerNameOnMainFormHere.AllowEdits = True
 
Thanks Bob,

Bearing in mind I am a mere novice at all this and have only got this far by cutting and pasting, do I replace my code with yours, or does it need to appear somewhere within my existing code?

Sorry to sound so stupid, but I am!
 
No, you aren't stupid - just because you don't have experience with something doesn't make you stupid - remember that! And, with subforms it can confuse the hell out of you as it did me and it took me several years to "get it."

You can copy and paste the code, but you will need to change the names as indicated in the code.

Change: YourMainFormNameHere to the actual name of your main form
Change: YourSubFormContainerNameOnMainFormHere to the actual name of the container on your main form that houses the subform. It most likely is the same name as your subform, but it could be different so select it and check.
 
Richie2837 said:
Sorry to sound so stupid, but I am!

Hey Richie,

My Dad always says, "a man looks good in his own world." Your just starting your adventure in Access so Bob looks really smart cause he can answer your questions but if Bob came into the world of what you know then he wouldn't look so smart, so with that being said, I agree with Bob, don't look at it as being stupid, just uninformed and that is what you have this forum for is to inform you. Folks like, Bob, are good people and help a bunch of folks like yourself. Just wanted to incourage you a little.

Hope your project goes well,
Shane
 
Thanks for the patience.

My code now looks like this:

Private Sub cmdEdit_Click()
Forms!Contacts.Form.Call History.AllowEdits = True
If Me.AllowEdits And Me.Dirty Then
Me.Dirty = False ' save record
End If


Me.AllowEdits = Not Me.AllowEdits ' toggle setting
' change the button's caption
cmdEdit.Caption = IIf(Me.AllowEdits, "Restrict Edits", "Edit Record")

End Sub

' always start with no editing allowed as each record is visited
Private Sub Form_Current()
Me.AllowEdits = False
cmdEdit.Caption = "Edit Record"
End Sub

But this is returning an error message. Any ideas what I've done wrong?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom