Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing / Allowing Edits 1

Status
Not open for further replies.

SherryLynn

Technical User
Feb 4, 2001
171
CA
In my database there is a main form for entering information on a family. When users open the form they search for a particular record and then prepare to edit it. I want to have the records "locked" while they search and then have them use a button on the main form to "unlock" it for editing. I would like the form to then lock again. How can I go about this? I am not very familiar with Visual Basic. Thanks for all your help.

Sherry
 
If you want to prevent changes to existing records (make a form read-only), set the AllowAdditions, AllowDeletions, and AllowEdits properties to No. You can also make records read-only by setting the RecordsetType property to Snapshot.

In the OnClick event of the button, try this:

Private Sub cmdUnlock_Click()

Me.AllowEdits = true
Me.AllowAdditions = true
Me.AllowDeletions = true

End Sub
 
Thanks for your response. What do I do next to allow the users to edit the record for data entry?
 
When the user selects the Unlock button, the OnClick event fires. Include the code in my previous post in the OnClick event of the Unlock button. That will allow the user to edit the data on the form. Set those properties to False to prevent the user from editing the data on the form.
 
Thank you. I will try that out. Thanks again for your help.

Sherry
 
Hi "Fancy",

I did what you suggested which worked great for locking the form. I wasn't sure where I needed to set the False values so here's what I did:

I created a command button on the form called Edit Record. As you suggested I placed the code in the button's OnClick event to set the values to True.

Then I created another button called Save Record in which I did the opposite - I set the values to False in the OnClick event of this button to save the record and lock the form again.

This worked very nicely until I clicked on my Add Record button. When I clicked on this button it brings up a blank form for entry for me, but my subform on this main form is no longer visible or active for data entry. Any ideas?

Thanks again.
Sherry
 
Does anyone have a solution to this problem? I still have not resolved this issue. Thanks so much.

Sherry
 
Have you tried to put the same kind of code in the Click event procedure of the Add record button as ihis of the Edit record one ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello,

I added the code you suggested to the Add Record click event procedure, but still get the same result. My subform does't show up? Any suggestions are much appreciated.

Thanks.
Sherry
 
I am also getting this message, "You can't go to the specified record. You may be at the end of a recordset"

Can anyone help me with this? Thanks to everyone who have taken the time already!

Sherry
 
Assuming you have form with a subform.

Why don't you post your code so we can take a look at it. Also, is your subform linked to the form correctly?
 
Hi Fancy,

Ok, I am adding the code from the AddRecord Button (I think that's what you mean). The main form is a "tabbed form" and has subforms on both pages. These all worked correctly normally, until I started adding these features. I don't know if that makes a difference. Here is the code:

Private Sub AddRecord_Click()
On Error GoTo Err_AddRecord_Click


DoCmd.GoToRecord , , acNewRec
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True

Exit_AddRecord_Click:
Exit Sub

Err_AddRecord_Click:
MsgBox Err.Description
Resume Exit_AddRecord_Click

End Sub


Help!

Thanks,
Sherry
 
don't have time right now to test your scnerio but, off hand, I would suggest changing your code around. Something like this:


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

Doevents

DoCmd.GoToRecord , , acNewRec
 
Hi there,

I tried changing the code to what you suggested, but I'm still having the same problem? I'm not sure what to do.

Thanks,
Sherry
 
I think I know what your problem might be.

The subform takes on the same atttibutes as the form. That is, if the property AllowAdditions is True for the form, it is also True for the subform. Likewise, if the AllowAdditions is False for the form, it is also False for the subform. It appears that you only set the properties for the form and not the subform.

Suppose your form name is frmFamily and the subform is named frmFamily_Members. The OnClick event that allows the user to edit the data would look like this:

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

frmFamily_Members.Form.AllowEdits = True
frmFamily_Members.Form.AllowAdditions = True
frmFamily_Members.Form.AllowDeletions = True

DoCmd.GoToRecord , , acNewRec

The OnClick event that turns it off would look like this:

Me.AllowEdits = False
Me.AllowAdditions = False
Me.AllowDeletions = False

frmFamily_Members.Form.AllowEdits = False
frmFamily_Members.Form.AllowAdditions = False
frmFamily_Members.Form.AllowDeletions = False
 
Hi Fancy,

Ok, I tried that out, but am getting an error.

Here is the code:

Private Sub EditRecord_Click()
Me.AllowEdits = True
Me.AllowAdditions = True
Me.AllowDeletions = True

Children2.Form.AllowEdits = True
Children2.Form.AllowAdditions = True
Children2.Form.AllowDeletions = True

End Sub

Children2 is the name of my subform.

I am getting this error:

"Compile Error: Variable not defined"

Do you know why this is happening?

Thanks
Sherry
 
When you created the form (Children2), you may have named it Children2. However, when you embedded it as a subform, it became a control on the form and Access renamed it. So check to see what the name of the subform control is.
 
Can you tell me exactly where I need to look for that? I'm a little confused. Thanks so much.

Sherry
 
The subform is a control on the form. Simply click on the subform and bring up the property sheet (if it isn't already displayed). The first 2 properties of the subform are "Name" and "Source Object". The "Source Object" should be the name of the form itself (Children2). The Name property is what you want to reference. If it is not Children2, then change it to Children2.
 
Hello Fancy,

Yeah!!! That was what it was. It worked just fine. I'll finish up the rest of the buttons and hopefully all will still work. Thanks so very much for your help.

Sherry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top