473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 21093
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,834 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,834 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,834 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, 269 views)
Feb 3 '11 #11
ADezii
8,834 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,834 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,834 Expert 8TB
You are quite welcome, sueb.
Feb 5 '11 #16

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

Similar topics

4
by: John Baker | last post by:
Hi: I have a query which supports a form. Te form is used to edit, update and change records in the table the query is based on. It all works fine EXCEPT that the "New" record (blank updatable...
2
by: chacquard | last post by:
Hi, I've been working on a form that contains a subform. The fields in the main form are EvendId, EventName, Date, time, place, etc.. These fields cannot be edited (locked = yes and...
7
by: Sally | last post by:
In a subform that has no records, what is the white area? If a subform has records and you scroll the records, what is the white area after the last record? I would like to be able to click in...
6
by: GSteven | last post by:
(as formerly posted to microsoft.public.access.forms with no result) I've created a continuous form which is based on a straightforward table (ex - customers - 100 records). On the form there is...
1
by: Eric E | last post by:
Hi all, I have a subform placed on a tab control, and I'm having a terrible time with proper tab order. I'm trying to allow the user to tab from the last control on my subform to a control on the...
8
by: Martin | last post by:
I hope not, but, I think the answer to this question is "it can't be done". Northwind sample database. Orders form. Go to a new record. Select a customer in "Bill To:" Don't enter any...
0
NeoPa
by: NeoPa | last post by:
Intention : To prepare a WHERE clause for multiple field selection, but to ignore any fields where the selection criteria are not set. ONLY WORKS WITH TEXT FIELD SELECTIONS. Scenario : You have...
3
by: Kelii | last post by:
I've been beating my head against this problem for the last several days, and I haven't found a decent solution yet. So I'm turning to the group for some moral support or better yet some answers. ...
25
by: tekctrl | last post by:
Anyone: I have a simple MSAccess DB which was created from an old ASCII flatfile. It works fine except for something that just started happening. I'll enter info in a record, save the record,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.