469,330 Members | 1,329 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,330 developers. It's quick & easy.

How to set a form's/subform's "Allow Edits" property?

sueb
379 256MB
I have a form/subform combination that I sometimes want to open disallowing Edits, Additions, and Deletions, depending on which password-protected menu option I'm coming from. (My menu structure is pretty simple, so I'm not using a switchboard, but rather some forms with controls on them.)

How do I manipulate those properties, of both the form and its subform, (in the little procedure that checks the password) before I open the form?
Jan 27 '11 #1

✓ answered by ADezii

I placed the following Code in the Open() Event of Patient_IUR_Overview, and it works fine:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.   If ReadOnly Then
  3.     Me![IURs1].Form.RecordsetType = conSnapshot
  4.   Else
  5.     Me![IURs1].Form.RecordsetType = conDynaset
  6.   End If
  7. End Sub

15 20296
beacon
579 512MB
Check out this link: http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx

It shows you how to access the the AllowEdits property in VBA. There are additional links and instruction for the other Allow-type properties.
Jan 29 '11 #2
sueb
379 256MB
That is a very helpful article. But I don't have the syntax correct for opening a form with its RecordsetType set to Snapshot. What I'm trying gives me a 'type mismatch':

Expand|Select|Wrap|Line Numbers
  1.     Dim stDocName As String
  2.     Dim stLinkCriteria As String
  3.  
  4.     stDocName = "Patient_IUR_Overview"
  5.  
  6.     ' Disallow Edits, Additions, and Deletions in both the Overview and Abbreviated forms
  7.     DoCmd.OpenForm stDocName, , , , RecordsetType = Snapshot, stLinkCriteria
  8.  
Feb 1 '11 #3
ADezii
8,800 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1. Dim strPassword As String
  2.  
  3. 'sueb will be able to Edit the Main Form (Orders) but NOT
  4. 'the SubForm (Orders SubForm)
  5. strPassword = "sueb"
  6.  
  7. Select Case strPassword
  8.   Case "Admininstrator"                             'Allow Main/SubForm Edits
  9.     Me.AllowEdits = True
  10.     Me![Orders SubForm].Form.AllowEdits = True
  11.   Case "sueb", "ADezii", "YaDa"                     'Allow Main Form Edits only
  12.     Me.AllowEdits = True
  13.     Me![Orders SubForm].Form.AllowEdits = False
  14.   Case "John", "Harry", "Peter", "Paul", "Mary"     'SubForm only
  15.     Me.AllowEdits = False
  16.     Me![Orders SubForm].Form.AllowEdits = True
  17. End Select
Feb 1 '11 #4
sueb
379 256MB
Oh, that's nice and tidy, ADezii, and I'm going to save it in my code treasure box.

However, currently my users don't sign in individually, and I'm trying a little different approach. My main menu offers three choices. Two of the choices share some forms in common, except that one choice allows you to edit the data and the other doesn't. I have a global constant ("ReadOnly") that the choices set appropriately, and the shared forms, in their "On Open" events, check that constant to see whether they should set their RecordsetType to "Snapshot" or not.

All the forms are working fine except for the subform on one of the forms. I can't seem to touch it properly. Here's how the main form behaves "On Open" (I got this from the link provided by beacon):

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Const conSnapshot = 2
  3.     If ReadOnly Then
  4.         Forms!Patient_IUR_Overview.RecordsetType = conSnapshot
  5.     End If
  6. End Sub
  7.  
but similar code in the subform's "On Open" event tells me that it can't find the form ("run-time error 2450"). I tried putting this code in "On Load" (what is the difference, anyway?), and tried referencing the subform within the main form's "On Open" event, all to no avail.
Feb 1 '11 #5
sueb
379 256MB
Any other ideas about how I can get this subform to set its RecordsetType when I open its parent form?
Feb 2 '11 #6
ADezii
8,800 Expert 8TB
I cannot understand why the following Code will not work:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.   'Set the RecordsetType of SubForm to Snapshot
  3.   Me![<SubForm_Name>].Form.RecordsetType = 2
  4. End Sub
Feb 2 '11 #7
sueb
379 256MB
I know I'm being completely dense about this, but I've tried a number of permutations of syntax (as you'll see in the following code, which contains only a fraction of them), and I just can't get this to stop saying it can't find either the subform (IURs_Abbreviate_subform) or the main form (Patient_IUR_Over). This code is in the subform; is it supposed to be in the main form or something? That seems weird to me, since the main form has no problem setting its own RecordsetType OnOpen.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     If ReadOnly Then
  3.         'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conSnapshot
  4.         'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
  5.         'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
  6.         Me![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
  7.     Else
  8.         'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conDynaset
  9.         'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
  10.         'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
  11.         Me![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
  12.     End If
  13. End Sub
  14.  
Feb 2 '11 #8
ADezii
8,800 Expert 8TB
Can you Upload a Scaled Down Version of the DB? It has to be something relatively simple.
Feb 2 '11 #9
sueb
379 256MB
Yes, ADezii, I'll do that tomorrow when I get back to work. Thanks!

And I'm sure you're right: it's got to be something simple that I'm just overlooking.
Feb 3 '11 #10
sueb
379 256MB
Here's a zip of my front end and a scrap of the back end. As you can see, I've moved from thinking about the AllowEdits, etc., properties to just trying to set the form's RecordsetType to Snapshot and Dynaset, as appropriate.

Thanks so much for all your help.
Attached Files
File Type: zip RecordsetType Question.zip (549.7 KB, 246 views)
Feb 3 '11 #11
ADezii
8,800 Expert 8TB
@sueb - It appears as though you were referring to the Source Object of the Sub-Form Control, instead of the Form Property of the Sub-Form Control itself. The Name of the Sub-Form Control is IURs1, while the Name of the Source Object for IURs1 is IURs_Abbreviated_subform. Try:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2. Const conSNAPSHOT As Byte = 2
  3. Const conDYNASET As Byte = 0
  4.  
  5. If ReadOnly Then
  6.   Me![IURs1].Form.RecordsetType = conSNAPSHOT
  7. Else
  8.   Me![IURs1].Form.RecordsetType = conDYNASET
  9. End If
  10. End Sub
Feb 3 '11 #12
sueb
379 256MB
I had actually previously noticed the name "IURs1" floating around (and wondered exactly when/where it was being created), and tried a stab at addressing it, but was certain I wasn't doing it correctly.

However, the lines you've given me don't seem to work either. I get an error (this time it's 2465) complaining that "Pre-Admitting IURs can't find the field 'IURs1' referred to in your expression."

I put this in the OnOpen event for the subform; was that right? (The constants are used by several forms, so they are declared publicly.)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     If ReadOnly Then
  3.         Me![IURs1].Form.RecordsetType = conSnapshot
  4.     Else
  5.         Me![IURs1].Form.RecordsetType = conDynaset
  6.     End If
  7. End Sub
Feb 5 '11 #13
ADezii
8,800 Expert 8TB
I placed the following Code in the Open() Event of Patient_IUR_Overview, and it works fine:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.   If ReadOnly Then
  3.     Me![IURs1].Form.RecordsetType = conSnapshot
  4.   Else
  5.     Me![IURs1].Form.RecordsetType = conDynaset
  6.   End If
  7. End Sub
Feb 5 '11 #14
sueb
379 256MB
AH! I did have it in the wrong OnOpen! Thanks so much for your patience, ADezii--it works great now!

I really need a reference that lays out neatly Access' contextual structure. There's so much that I'm unclear on (and I'm usually pretty good about this kind of thing--I just have nothing to even start with!)

Thanks again!
Feb 5 '11 #15
ADezii
8,800 Expert 8TB
You are quite welcome, sueb.
Feb 5 '11 #16

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by chacquard | last post: by
7 posts views Thread by Sally | last post: by
1 post views Thread by Eric E | last post: by
8 posts views Thread by Martin | last post: by
25 posts views Thread by tekctrl | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.