-
[RESOLVED] Create an EDIT on/off button
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?
Editable:
Yes (*)
No ()
VB Code:
'edit on/off
Private Sub Edit_AfterUpdate()
If Me.Edit = 1 Then
'on
Me.Form.AllowEdits = True
ElseIf Me.Edit = 2 Then
'off
Me.Form.AllowEdits = False
End If
End Sub
-
Re: Create an EDIT on/off button
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.
-
Re: Create an EDIT on/off button
Quote:
Originally Posted by salvelinus
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 ??
-
Re: Create an EDIT on/off button
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)
-
Re: Create an EDIT on/off button
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.
-
Re: Create an EDIT on/off button
I tried Forms!frm_sociaal
but it won't work :/
-
Re: Create an EDIT on/off button
Try Forms!frm_sociaal!allowEdits
-
1 Attachment(s)
Re: Create an EDIT on/off button
It seems like the files aren't connected or something because they aren't
even in the list with variables
so i can't even choose/ use them not even with
VB Code:
Forms!frm_sociaal!allowEdits = true
-
Re: Create an EDIT on/off button
Well, for one thing, you can't set a subforms AllowEdit property:
Quote:
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:
Quote:
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.
-
Re: Create an EDIT on/off button
I tried i but didn't get any wiser :ehh:
still a thing i don't get why does it work with frm_contactadres?
and not the others...
-
Re: Create an EDIT on/off button
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.
-
Re: Create an EDIT on/off button
I don't get it i tried everything you told me and what the help function said but it won't work.
"can't find the form you are reffering to"
-
Re: Create an EDIT on/off button
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?
-
Re: Create an EDIT on/off button
I just can't figure out why i can't see the forms when i'm in VBA checked spelling
it's just that they won't appear in the options list
http://www.vbforums.com/attachment.p...id=46607&stc=1
-
Re: Create an EDIT on/off button
Well, at that point in the screenshot you want to select frm_contactadres, then the subform.
-
Re: Create an EDIT on/off button
so it would be me.frm_contactadres.<subform name??>.enabled = false
i'm gonna try it tommorow i'm going home get some diner
-
1 Attachment(s)
Re: Create an EDIT on/off button
Another day another try.
I've read trough this whole topic over and over to look if i might over read something and i'm gonna try this again now:
VB Code:
Private Sub Command0_Click()
Forms!form2!Child3.Enabled = False
End Sub
because what it says is that
Form2 = main file
Child3 = subform
My frm's still aren't in the Object Browser
but it might be i will be able to link it correct in one way or the other
_____________________________
|Also this time i included the file!
|might be more helpfull.
-
Re: Create an EDIT on/off button
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.
-
Re: Create an EDIT on/off button
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
Here you can find Winrar it opens most compressed file types:
http://www.rarlab.com/rar/wrar351.exe
I keep getting this error code by the way maybe you got some idea when you see it:
Code:
Run-time error '2465'
Microsoft Access cannot find the field 'frmLogon' referred to in your expression
I looked it up and i got this solution on these forums but it won't work as well
VB Code:
Forms!MainFormName!SubFormControlName.Form!ControlName
-
Re: Create an EDIT on/off button
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
If Me.Edit = 1 Then
Me.Tabbest.Pages("pagina49").Controls(0).Enabled = False
'etc
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.
-
Re: Create an EDIT on/off button
VB Code:
'I changed the name of the tab control for my own convenience
If Me.Edit = 1 Then
Me.Tabbest.Pages("pagina49").Controls(0).Enabled = False
'etc
Tabbest = name of tablist
pages = command
"pagina49" = refers to a page name
because now i get error 438
this property or methode isn't supported by this object
-
Re: Create an EDIT on/off button
I don't know why, works fine for me.
I'll have to reread this thread, I forgot what the original intention was. :ehh:
-
Re: Create an EDIT on/off button
you try it with an new pagenumber
but can you get it to work with an existing sub_form???
sorry for all the qustions, i'm just a VB beginner.
-
Re: Create an EDIT on/off button
Thank you Salvelinus for all the tips and idea's
my final and working solution:
VB Code:
'Bewerken aan uit
Private Sub Edit_click()
'aan
If Me.Edit = 1 Then
Me.Tablist.Pages(0).Enabled = True
Me.Tablist.Pages(1).Enabled = True
Me.Tablist.Pages(2).Enabled = True
Me.Tablist.Pages(3).Enabled = True
Me.Tablist.Pages(4).Enabled = True
Me.Tablist.Pages(5).Enabled = True
Me.Tablist.Pages(6).Enabled = True
Me.Achternaam.Locked = False
Me.Voornaam.Locked = False
Me.Geboortedatum.Locked = False
Me.geslacht.Locked = False
Me.toevoeging.Locked = False
MsgBox "Bewerken ingeschakeld.", vbExclamation, "Bewerken aan"
'uit
ElseIf Me.Edit = 2 Then
Me.Tablist.Pages(0).Enabled = False
Me.Tablist.Pages(1).Enabled = False
Me.Tablist.Pages(2).Enabled = False
Me.Tablist.Pages(3).Enabled = False
Me.Tablist.Pages(4).Enabled = False
Me.Tablist.Pages(5).Enabled = False
Me.Tablist.Pages(6).Enabled = False
Me.Achternaam.Locked = True
Me.Voornaam.Locked = True
Me.Geboortedatum.Locked = True
Me.geslacht.Locked = True
Me.toevoeging.Locked = True
MsgBox "Bewerken uitgeschakeld.", vbInformation, "Bewerken uit"
End If
End Sub
-
Re: [RESOLVED] Create an EDIT on/off button
Great. You could shorten the code a bit by using a For...Each, if you wanted. Not necessary, just an option.
VB Code:
Private Sub Edit_click()
Dim p as Page
'aan
If Me.Edit = 1 Then
With Me.Tablist.
For Each p in .Pages
.Enabled = True
Next
End With
'alternately
For Each p in Me.Tablist.Pages
.Enabled = True
Next
'etc