I got a program and i wan't to build in an option that users
first need to select the option editable ON.
so far i got a script but it won't work with subforms and it even disables
the option buttons. i need to get it something like CurrentRecord.
Anyone have an idea?
You could just disable whatever particular controls you want, rather than the whole form. Also, since a subform is actually another form, you'd have to disable that explicitly - Forms!frmSubFormFoo, etc.
You could just disable whatever particular controls you want, rather than the whole form. Also, since a subform is actually another form, you'd have to disable that explicitly - Forms!frmSubFormFoo, etc.
There are to many controls to disable by hand it would be a
very large script file.
I just need them to be able to READ-only when opening the program and set
editable: Yes to start editting.
I got about 8 subforms, how do i define those in a script
Forms!frm_cognitief.AllowEdits = False ??
OK i made some changes.
all subforms will open with AllowEdits = False
when i press the button editable: Yes (*)
No ()
all the forms need to be cleared AllowEdits = True
VB Code:
'Bewerken aan uit
Private Sub Edit_click()
'aan
If Me.Edit = 1 Then
'Me!frm_andereaandacht.Form.AllowEdits = True
'Me!frm_cognitief.Form.AllowEdits = True
Me!frm_contactadres.Form.AllowEdits = True
'Me!frm_lichamelijk.Form.AllowEdits = True
'Me!frm_medisch.Form.AllowEdits = True
'Me!frm_overdracht.Form.AllowEdits = True
'Me!frm_sociaal.Form.AllowEdits = True
Me.Achternaam.Locked = False
Me.Voornaam.Locked = False
Me.Geboortedatum.Locked = False
Me.geslacht.Locked = False
Me.toevoeging.Locked = False
MsgBox "U kunt nu gegevens bewerken.", vbExclamation, "Bewerken aan"
'uit
ElseIf Me.Edit = 2 Then
'Me!frm_andereaandacht.Form.AllowEdits = False
'Me!frm_cognitief.Form.AllowEdits = False
Me!frm_contactadres.Form.AllowEdits = False
'Me!frm_lichamelijk.Form.AllowEdits = False
'Me!frm_medisch.Form.AllowEdits = False
'Me!frm_overdracht.Form.AllowEdits = False
'Me!frm_sociaal.Form.AllowEdits = False
Me.Achternaam.Locked = True
Me.Voornaam.Locked = True
Me.Geboortedatum.Locked = True
Me.geslacht.Locked = True
Me.toevoeging.Locked = True
MsgBox "De optie om gegevens te bewerken is uitgeschakeld.", vbInformation, "Bewerken uit"
End If
End Sub
all the frm_ files are my subforms.
But when i run the script it says it doesn't recognise the forms
- frm_andereaandacht
- frm_cognitief
- frm_lichamelijk
- frm_medisch
- frm_overdracht
- frm_sociaal
I included the program the main form is frm_test2
(it's all dutch hope you can fidle it out)
Last edited by valentinorossi; Apr 4th, 2006 at 05:34 AM.
I don't use subforms that often, so I'm half guessing here, but it may be because the subforms don't come under the Me keyword, since that refers to the active form, and a subform is another form contained in that form, but not an actual control on the form. That's why I suggested the Forms!frm_sociaal... notation for the subforms.
Well, for one thing, you can't set a subforms AllowEdit property:
Subform/Subreport Control Properties
The following list identifies the properties you can set for a subform/subreport control. Those properties that apply only when the control is on a form are followed by (forms) for "Forms Only."
Click any name below to display additional information about that property, such as other restrictions concerning when the property is available, and whether you can set it in the property sheet, in a macro, or by using Visual Basic.
AddColon LinkChildFields
AutoLabel LinkMasterFields
BorderColor Locked (forms)
BorderStyle Name
BorderWidth OnEnter (forms)
CanGrow OnExit (forms)
CanShrink SourceObject
ControlType SpecialEffect
DisplayWhen (forms) StatusBarText (forms)
Enabled (forms) TabIndex (forms)
Height TabStop (forms)
InSelection (forms) Tag
LabelAlign Top
LabelX Visible
LabelY Width
Left
Also:
Refer to a form, report, subform, or subreport in an expression
You refer to an open form or report, or the subform or subreport of an open form or report, in an expression by typing its identifier.
To refer to an open form or report
Type the name of the Forms or Reports collection, followed by the ! operator and the name of the form or report. For example, the following identifier refers to the Orders form:
Forms![Orders]
To refer to a subform or subreport
Refer to the subform or subreport control on the form or report that contains the subform or subreport, then use the Form or Report property of the control to refer to the actual subform or subreport.
Type the identifier for the form that contains the subform, followed by the name of its subform control, the . (dot) operator, and the Form property. For example, the following identifier refers to the Orders Subform subform on the Orders form:
Forms![Orders]![Orders Subform].Form
Notes
You can use the Expression Builder to create an identifier for a form, report, subform, or subreport.
When you run a macro or Visual Basic for Applications code containing an expression that refers to a form or report, the form or report must be open.
I didn't know this stuff either. Type subform in the Help index for a list of other topics. This also shows an easier way of setting the properties on the controls on the form - iterate through the Controls collection, and set the property if the name isn't one(s) you want left alone.
Kind of contrary to what I wrote before, the subform is referred to under your main form, frm_contactadres. So to refer to a subform:
Code:
Forms!frm_contactadres!frm_sociaal.Enabled = False 'since you can't use .AllowEdits
'or maybe
Forms!frm_contactadres!frm_sociaal.Form.Enabled = False 'don't know why the example has the extra .Form at the end.
Well, don't know then, sorry. Check your spelling, maybe try doing the subforms before you disable the main form.
edit:
I just did this on a test form, and it worked for me:
VB Code:
Private Sub Command0_Click()
Forms!form2!Child3.Enabled = False
End Sub
Before clicking the button, the subform was enabled. After, it wasn't.
of course, the subform also shows up in the Object Browser; I searched for "child3" under all libraries. It also worked even when Form2 was disabled first. So my guess, if you can't find your form on the OB, is that something's wrong there. Are the subforms actual forms you created and set as the source object for the subform?
Last edited by salvelinus; Apr 4th, 2006 at 09:30 AM.
Sorry, I don't have anything to unzip a .rar file.
The form I'm using for a subform is named abc, in the form pane of the database. The subform is called Child3 (a default name), and the form called abc is set as the control source. I don't use the form name, abc, in the code, I use the subform name, Child3. So if you have an actual form named frm_sociaal, you wouldn't use that name, except as the control source for whatever your subform is called. In code, use the name of the subform to reference it. You could also use Me.yoursubformname.enabled in this case. For example, if I type Me., Child3 is an option in Intellisense.
Now, if your actual subform is named frm_sociaal, I don't know why it wouldn't work.
Last edited by salvelinus; Apr 5th, 2006 at 07:58 AM.
The subform is indeed called frm_sociaal so i can't figure it out why the code seems to
be correct even when i check it with the help function an what options you gave me
but it can't seem to open it.
I Rarred it because a Zip file was 92kb too big maximum upload size is 500kb
Yes, I see now. You have the subforms on pages in a tab control. You have to reference the controls collection of the page of the tab
Try something like this:
VB Code:
'I changed the name of the tab control for my own convenience
In the help file, you may want to look up tab control & page object if I'm not clear. Pages are in a collection, so you can use For..Each to iterate through them all as well.