PDA

View Full Version : Solved: Why won't my AllowEdits property work?



self_teachin01
02-01-2005, 12:05 PM
Hello everyone. This is my first post and I'm grateful for the help in advance. I'm learning VBA on the fly with no mentor, just one badly written book and a lot of trial and error, so the answer is probably some obvious thing I missed.

I have a sequential multi-form data entry process for a database I'm building. I've been trying to limit access to editing prior records to only upon a certain button press, and then only to a given subset of records based on entries in a prior form.

My buttons to intiate this "edit mode" where edit access is granted and to return to "view mode" where it's not granted work fine. The problem is that the form is supposed to *open* in viewonly mode, and it refuses to - opens in Edit Mode every time. The very same commands that successfully turn edit access on and off as events of On_Click
for some reason will not obey in On_Load or even On_Unload. At one point I had 3 redundant commands and yet, every time I open this form I can edit the records until I begin using the "Edit Mode" and "View Mode" buttons.

I'm posting all relevant code sections below, including the button from the prior form that opens the one I'm discussing. What I believed were my redundant commands to make sure the form opens in non-edit-mode are in bold, as are the button commands to switch to non-edit and back that do work

Note that I know that I could just manually set the form properties to default AllowEdit = No and AllowAdditions = No. But that doesn't explain why code that should work doesn't.

Code - Initial Form Button To Open Main Form

Private Sub CoverNewSkills_Click()
On Error GoTo Err_CoverNewSkills_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Basic Activity Info (S)"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly, , Me.CICADUNITMASTER.Value

DoCmd.Close acForm, "Cover A"
Exit_CoverNewSkills_Click:
Exit Sub

Code: Main Form (On_Load, On_Unload, On_Click of Edit Mode/View Mode Button)

Private Sub Form_Load()
Me.CICADValueStorage = Me.OpenArgs
Me.AddRecord.Visible = False
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False

Private Sub Form_Unload(Cancel As Integer)
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
DoCmd.OpenForm ("Institutions (S)"), , , , acFormEdit
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False

Private Sub EditMode_Click()
If EditMode.Caption = "Go To Edit Mode" Then
If Me.OpenArgs = Me.CICADUnitBasicS Then

Me.Form.RecordSource = "SELECT * FROM WHERE _
[Basic Activity Info (S)].CICADUnitBasicS = Forms![Basic Activity Info (S)]! _
[CICADUnitBasicS]"
EditMode.Caption = "Return to View Mode"
[b]Me.Form.AllowEdits = True
Me.Form.AllowAdditions = True
Me.AddRecord.Visible = True
Else: MsgBox ("You can only edit records from the unit that " & _
"you selected in the initial setup screen.")
End If
Else
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Me.AddRecord.Visible = False
End If
End Sub


So why on earth won't it work? It seems like this sort of think happens to me every day learning this language, and boy is it frustrating.

Thanks,
self_teachin01

UPDATE: (2PM)
One tiny piece of information that may or may not help:

The first time I add one of these controls in and then try to open the form through the prior form, I get an error message saying "The OpenForm Action was canceled." If I open the form directly (skipping the readonly command, maybe?), close it again, and then go in the correct way (through the prior form) there is no error message and it opens in the wrong mode like before.

self_teachin01
02-03-2005, 11:34 AM
Never mind, guys. I solved it myself, several days later. In my OnLoad event, I had a command to write data into a control.... of course that would nullify my ReadOnly setting in the prior OpenForm command, as well as the earlier ones..

Nobody replied to my post while it was open. If anyone can provide insight as to what about my post made it a bad one to get responses, I'd be grateful. I'd like to be able to use this resource for other questions.

Thanks.

Anne Troy
02-16-2005, 02:34 PM
I am working very hard to get Access VBA experts on our forum, teachin. I'm sooo sorry. And so glad you got this one solved.

downwitch
02-17-2005, 04:26 AM
Dreamy's not kidding, she's recruiting.

Three things: First this, from Access online help about the AllowEdits property
When the Data Mode argument of the OpenForm action is set, Microsoft Access will override a number of form property settings. If the Data Mode argument of the OpenForm action is set to Edit, Microsoft Access will open the form with the following property settings:
AllowEdits — Yes
AllowDeletions — Yes
AllowAdditions — Yes
DataEntry — No Not sure if that's what you meant by using read-only on the open form call, but there you go.

Secondly, your code looks, erm, strange. Why is it indented like that? And where are the End Sub statements? Perhaps you've only posted it like this for the forum, but in general, easy-to-read code looks like this
Private Sub My_Thang()
'stuff
'nested stuff
End Sub

Private Sub My_Other_Thang()
'still more stuff
End SubAnd finally, if you set the form's "Allow Design Changes" property to "Design View Only", there is no need to reset those Allow properties on unload.

Hope that gives you some insight.

Anne Troy
02-17-2005, 05:30 AM
I wondered about the indentation myself, down. I did manage to tweak the code a very little bit to keep it from causing horizontal scroll bars across the page, but only added the underscore to one line, I think, and brought the one comment back outside VBA tags.

Anyway, down, thanks soooo much for helping out!! I'm sure you understand the frustration of knowing there's people who can answer these questions, but they sit here... Someone else has indicated that they could help out a lot, too, so hopefully we'll have it covered. Thanks again!

self_teachin01
03-07-2005, 03:30 PM
I think i just indent because, like i said, i taught myself and no one taught me not to. It helps me separate commands. I'll remember that it's unpopular.

Down, I'm aware of those form properties, so this answer was not what I was looking for. But thanks for trying.

I have a new problem. Maybe I'll have better luck.