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?
I placed the following Code in the Open() Event of Patient_IUR_Overview, and it works fine: - Private Sub Form_Open(Cancel As Integer)
-
If ReadOnly Then
-
Me![IURs1].Form.RecordsetType = conSnapshot
-
Else
-
Me![IURs1].Form.RecordsetType = conDynaset
-
End If
-
End Sub
15 21093
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': - Dim stDocName As String
-
Dim stLinkCriteria As String
-
-
stDocName = "Patient_IUR_Overview"
-
-
' Disallow Edits, Additions, and Deletions in both the Overview and Abbreviated forms
-
DoCmd.OpenForm stDocName, , , , RecordsetType = Snapshot, stLinkCriteria
-
- Dim strPassword As String
-
-
'sueb will be able to Edit the Main Form (Orders) but NOT
-
'the SubForm (Orders SubForm)
-
strPassword = "sueb"
-
-
Select Case strPassword
-
Case "Admininstrator" 'Allow Main/SubForm Edits
-
Me.AllowEdits = True
-
Me![Orders SubForm].Form.AllowEdits = True
-
Case "sueb", "ADezii", "YaDa" 'Allow Main Form Edits only
-
Me.AllowEdits = True
-
Me![Orders SubForm].Form.AllowEdits = False
-
Case "John", "Harry", "Peter", "Paul", "Mary" 'SubForm only
-
Me.AllowEdits = False
-
Me![Orders SubForm].Form.AllowEdits = True
-
End Select
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): - Private Sub Form_Open(Cancel As Integer)
-
Const conSnapshot = 2
-
If ReadOnly Then
-
Forms!Patient_IUR_Overview.RecordsetType = conSnapshot
-
End If
-
End Sub
-
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.
Any other ideas about how I can get this subform to set its RecordsetType when I open its parent form?
I cannot understand why the following Code will not work: - Private Sub Form_Open(Cancel As Integer)
-
'Set the RecordsetType of SubForm to Snapshot
-
Me![<SubForm_Name>].Form.RecordsetType = 2
-
End Sub
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. - Private Sub Form_Open(Cancel As Integer)
-
If ReadOnly Then
-
'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conSnapshot
-
'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
-
'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
-
Me![IURs_Abbreviated_subform].Form.RecordsetType = conSnapshot
-
Else
-
'Forms!Patient_IUR_Overview!IURs_Abbreviated_subform.RecordsetType = conDynaset
-
'Forms![Patient_IUR_Overview]![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
-
'Forms![Patient_IUR_Overview].[IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
-
Me![IURs_Abbreviated_subform].Form.RecordsetType = conDynaset
-
End If
-
End Sub
-
Can you Upload a Scaled Down Version of the DB? It has to be something relatively simple.
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.
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.
@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: -
Private Sub Form_Open(Cancel As Integer)
-
Const conSNAPSHOT As Byte = 2
-
Const conDYNASET As Byte = 0
-
-
If ReadOnly Then
-
Me![IURs1].Form.RecordsetType = conSNAPSHOT
-
Else
-
Me![IURs1].Form.RecordsetType = conDYNASET
-
End If
-
End Sub
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.) - Private Sub Form_Open(Cancel As Integer)
-
If ReadOnly Then
-
Me![IURs1].Form.RecordsetType = conSnapshot
-
Else
-
Me![IURs1].Form.RecordsetType = conDynaset
-
End If
-
End Sub
I placed the following Code in the Open() Event of Patient_IUR_Overview, and it works fine: - Private Sub Form_Open(Cancel As Integer)
-
If ReadOnly Then
-
Me![IURs1].Form.RecordsetType = conSnapshot
-
Else
-
Me![IURs1].Form.RecordsetType = conDynaset
-
End If
-
End Sub
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!
You are quite welcome, sueb.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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.
...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |