Results 1 to 25 of 25

Thread: [RESOLVED] Create an EDIT on/off button

  1. #1

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    Resolved [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:
    1. 'edit on/off
    2. Private Sub Edit_AfterUpdate()
    3.  
    4.     If Me.Edit = 1 Then
    5.        'on
    6.         Me.Form.AllowEdits = True
    7.      ElseIf Me.Edit = 2 Then
    8.          'off
    9.          Me.Form.AllowEdits = False
    10.     End If
    11. End Sub

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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.
    Tengo mas preguntas que contestas

  3. #3

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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 ??

  4. #4

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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:
    1. 'Bewerken aan uit
    2. Private Sub Edit_click()
    3.    
    4.    'aan
    5.     If Me.Edit = 1 Then
    6.         'Me!frm_andereaandacht.Form.AllowEdits = True
    7.         'Me!frm_cognitief.Form.AllowEdits = True
    8.         Me!frm_contactadres.Form.AllowEdits = True
    9.         'Me!frm_lichamelijk.Form.AllowEdits = True
    10.         'Me!frm_medisch.Form.AllowEdits = True
    11.         'Me!frm_overdracht.Form.AllowEdits = True
    12.         'Me!frm_sociaal.Form.AllowEdits = True
    13.         Me.Achternaam.Locked = False
    14.         Me.Voornaam.Locked = False
    15.         Me.Geboortedatum.Locked = False
    16.         Me.geslacht.Locked = False
    17.         Me.toevoeging.Locked = False
    18.          
    19.           MsgBox "U kunt nu gegevens bewerken.", vbExclamation, "Bewerken aan"
    20.     'uit
    21.      ElseIf Me.Edit = 2 Then
    22.           'Me!frm_andereaandacht.Form.AllowEdits = False
    23.           'Me!frm_cognitief.Form.AllowEdits = False
    24.           Me!frm_contactadres.Form.AllowEdits = False
    25.           'Me!frm_lichamelijk.Form.AllowEdits = False
    26.           'Me!frm_medisch.Form.AllowEdits = False
    27.           'Me!frm_overdracht.Form.AllowEdits = False
    28.           'Me!frm_sociaal.Form.AllowEdits = False
    29.           Me.Achternaam.Locked = True
    30.           Me.Voornaam.Locked = True
    31.           Me.Geboortedatum.Locked = True
    32.           Me.geslacht.Locked = True
    33.           Me.toevoeging.Locked = True
    34.            
    35.             MsgBox "De optie om gegevens te bewerken is uitgeschakeld.", vbInformation, "Bewerken uit"
    36.     End If
    37. 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.

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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.
    Tengo mas preguntas que contestas

  6. #6

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    Re: Create an EDIT on/off button

    I tried Forms!frm_sociaal

    but it won't work :/

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Create an EDIT on/off button

    Try Forms!frm_sociaal!allowEdits
    Tengo mas preguntas que contestas

  8. #8

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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:
    1. Forms!frm_sociaal!allowEdits = true
    Attached Images Attached Images  
    When all else fails..... go get some coffee

  9. #9
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Create an EDIT on/off button

    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.
    Tengo mas preguntas que contestas

  10. #10

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    Re: Create an EDIT on/off button

    I tried i but didn't get any wiser

    still a thing i don't get why does it work with frm_contactadres?
    and not the others...
    When all else fails..... go get some coffee

  11. #11
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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.
    Tengo mas preguntas que contestas

  12. #12

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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"
    When all else fails..... go get some coffee

  13. #13
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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:
    1. Private Sub Command0_Click()
    2.       Forms!form2!Child3.Enabled = False
    3. 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.
    Tengo mas preguntas que contestas

  14. #14

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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
    When all else fails..... go get some coffee

  15. #15
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Create an EDIT on/off button

    Well, at that point in the screenshot you want to select frm_contactadres, then the subform.
    Tengo mas preguntas que contestas

  16. #16

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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
    When all else fails..... go get some coffee

  17. #17

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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:
    1. Private Sub Command0_Click()
    2.       Forms!form2!Child3.Enabled = False
    3. 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.
    Attached Files Attached Files
    When all else fails..... go get some coffee

  18. #18
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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.
    Last edited by salvelinus; Apr 5th, 2006 at 07:58 AM.
    Tengo mas preguntas que contestas

  19. #19

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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:
    1. Forms!MainFormName!SubFormControlName.Form!ControlName
    Last edited by valentinorossi; Apr 5th, 2006 at 08:37 AM.
    When all else fails..... go get some coffee

  20. #20
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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:
    1. 'I changed the name of the tab control for my own convenience
    2. If Me.Edit = 1 Then
    3.         Me.Tabbest.Pages("pagina49").Controls(0).Enabled = False
    4.         '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.
    Tengo mas preguntas que contestas

  21. #21

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    Re: Create an EDIT on/off button

    VB Code:
    1. 'I changed the name of the tab control for my own convenience
    2. If Me.Edit = 1 Then
    3.         Me.Tabbest.Pages("pagina49").Controls(0).Enabled = False
    4.         '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
    When all else fails..... go get some coffee

  22. #22
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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.
    Tengo mas preguntas que contestas

  23. #23

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    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.
    When all else fails..... go get some coffee

  24. #24

    Thread Starter
    Junior Member valentinorossi's Avatar
    Join Date
    Apr 2006
    Location
    Holland
    Posts
    18

    Re: Create an EDIT on/off button

    Thank you Salvelinus for all the tips and idea's


    my final and working solution:

    VB Code:
    1. 'Bewerken aan uit
    2. Private Sub Edit_click()
    3.    
    4.    'aan
    5.     If Me.Edit = 1 Then
    6.         Me.Tablist.Pages(0).Enabled = True
    7.         Me.Tablist.Pages(1).Enabled = True
    8.         Me.Tablist.Pages(2).Enabled = True
    9.         Me.Tablist.Pages(3).Enabled = True
    10.         Me.Tablist.Pages(4).Enabled = True
    11.         Me.Tablist.Pages(5).Enabled = True
    12.         Me.Tablist.Pages(6).Enabled = True
    13.         Me.Achternaam.Locked = False
    14.         Me.Voornaam.Locked = False
    15.         Me.Geboortedatum.Locked = False
    16.         Me.geslacht.Locked = False
    17.         Me.toevoeging.Locked = False
    18.          
    19.           MsgBox "Bewerken ingeschakeld.", vbExclamation, "Bewerken aan"
    20.     'uit
    21.      ElseIf Me.Edit = 2 Then
    22.         Me.Tablist.Pages(0).Enabled = False
    23.         Me.Tablist.Pages(1).Enabled = False
    24.         Me.Tablist.Pages(2).Enabled = False
    25.         Me.Tablist.Pages(3).Enabled = False
    26.         Me.Tablist.Pages(4).Enabled = False
    27.         Me.Tablist.Pages(5).Enabled = False
    28.         Me.Tablist.Pages(6).Enabled = False
    29.         Me.Achternaam.Locked = True
    30.         Me.Voornaam.Locked = True
    31.         Me.Geboortedatum.Locked = True
    32.         Me.geslacht.Locked = True
    33.         Me.toevoeging.Locked = True
    34.            
    35.             MsgBox "Bewerken uitgeschakeld.", vbInformation, "Bewerken uit"
    36.     End If
    37. End Sub
    When all else fails..... go get some coffee

  25. #25
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    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:
    1. Private Sub Edit_click()
    2.    Dim p as Page    
    3.    'aan
    4.     If Me.Edit = 1 Then
    5.         With Me.Tablist.
    6.              For Each p in .Pages
    7.                  .Enabled = True
    8.              Next
    9.         End With
    10.         'alternately
    11.         For Each p in Me.Tablist.Pages
    12.             .Enabled = True
    13.         Next
    14.     'etc
    Tengo mas preguntas que contestas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width