Consulting

Results 1 to 6 of 6

Thread: Solved: Why won't my AllowEdits property work?

  1. #1

    Exclamation Solved: Why won't my AllowEdits property work?

    Hello everyone. This is my first post and I'm grateful for the help in advance. I'm learning VBA on the fly with no mentor, just one badly written book and a lot of trial and error, so the answer is probably some obvious thing I missed.

    I have a sequential multi-form data entry process for a database I'm building. I've been trying to limit access to editing prior records to only upon a certain button press, and then only to a given subset of records based on entries in a prior form.

    My buttons to intiate this "edit mode" where edit access is granted and to return to "view mode" where it's not granted work fine. The problem is that the form is supposed to *open* in viewonly mode, and it refuses to - opens in Edit Mode every time. The very same commands that successfully turn edit access on and off as events of On_Click
    for some reason will not obey in On_Load or even On_Unload. At one point I had 3 redundant commands and yet, every time I open this form I can edit the records until I begin using the "Edit Mode" and "View Mode" buttons.

    I'm posting all relevant code sections below, including the button from the prior form that opens the one I'm discussing. What I believed were my redundant commands to make sure the form opens in non-edit-mode are in bold, as are the button commands to switch to non-edit and back that do work

    Note that I know that I could just manually set the form properties to default AllowEdit = No and AllowAdditions = No. But that doesn't explain why code that should work doesn't.

    Code - Initial Form Button To Open Main Form

    [VBA] Private Sub CoverNewSkills_Click()
    On Error GoTo Err_CoverNewSkills_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Basic Activity Info (S)"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly, , Me.CICADUNITMASTER.Value

    DoCmd.Close acForm, "Cover A"
    Exit_CoverNewSkills_Click:
    Exit Sub[/vba]

    Code: Main Form (On_Load, On_Unload, On_Click of Edit Mode/View Mode Button)

    [vba]Private Sub Form_Load()
    Me.CICADValueStorage = Me.OpenArgs
    Me.AddRecord.Visible = False
    Me.Form.AllowEdits = False
    Me.Form.AllowAdditions = False

    Private Sub Form_Unload(Cancel As Integer)
    Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
    EditMode.Caption = "Go To Edit Mode"
    DoCmd.OpenForm ("Institutions (S)"), , , , acFormEdit
    Me.Form.AllowEdits = False
    Me.Form.AllowAdditions = False

    Private Sub EditMode_Click()
    If EditMode.Caption = "Go To Edit Mode" Then
    If Me.OpenArgs = Me.CICADUnitBasicS Then

    Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)] WHERE _
    [Basic Activity Info (S)].CICADUnitBasicS = Forms![Basic Activity Info (S)]! _
    [CICADUnitBasicS]"
    EditMode.Caption = "Return to View Mode"
    Me.Form.AllowEdits = True
    Me.Form.AllowAdditions = True
    Me.AddRecord.Visible = True
    Else: MsgBox ("You can only edit records from the unit that " & _
    "you selected in the initial setup screen.")
    End If
    Else
    Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
    EditMode.Caption = "Go To Edit Mode"
    Me.Form.AllowEdits = False
    Me.Form.AllowAdditions = False
    Me.AddRecord.Visible = False
    End If
    End Sub[/VBA]


    So why on earth won't it work? It seems like this sort of think happens to me every day learning this language, and boy is it frustrating.

    Thanks,
    self_teachin01

    UPDATE: (2PM)
    One tiny piece of information that may or may not help:

    The first time I add one of these controls in and then try to open the form through the prior form, I get an error message saying "The OpenForm Action was canceled." If I open the form directly (skipping the readonly command, maybe?), close it again, and then go in the correct way (through the prior form) there is no error message and it opens in the wrong mode like before.

  2. #2
    Never mind, guys. I solved it myself, several days later. In my OnLoad event, I had a command to write data into a control.... of course that would nullify my ReadOnly setting in the prior OpenForm command, as well as the earlier ones..

    Nobody replied to my post while it was open. If anyone can provide insight as to what about my post made it a bad one to get responses, I'd be grateful. I'd like to be able to use this resource for other questions.

    Thanks.

  3. #3
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I am working very hard to get Access VBA experts on our forum, teachin. I'm sooo sorry. And so glad you got this one solved.
    ~Anne Troy

  4. #4
    Dreamy's not kidding, she's recruiting.

    Three things: First this, from Access online help about the AllowEdits property
    When the Data Mode argument of the OpenForm action is set, Microsoft Access will override a number of form property settings. If the Data Mode argument of the OpenForm action is set to Edit, Microsoft Access will open the form with the following property settings:
    AllowEdits — Yes
    AllowDeletions — Yes
    AllowAdditions — Yes
    DataEntry — No
    Not sure if that's what you meant by using read-only on the open form call, but there you go.

    Secondly, your code looks, erm, strange. Why is it indented like that? And where are the End Sub statements? Perhaps you've only posted it like this for the forum, but in general, easy-to-read code looks like this
    Private Sub My_Thang()
        'stuff
            'nested stuff
    End Sub
    
    Private Sub My_Other_Thang()
        'still more stuff
    End Sub
    And finally, if you set the form's "Allow Design Changes" property to "Design View Only", there is no need to reset those Allow properties on unload.

    Hope that gives you some insight.

  5. #5
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    I wondered about the indentation myself, down. I did manage to tweak the code a very little bit to keep it from causing horizontal scroll bars across the page, but only added the underscore to one line, I think, and brought the one comment back outside VBA tags.

    Anyway, down, thanks soooo much for helping out!! I'm sure you understand the frustration of knowing there's people who can answer these questions, but they sit here... Someone else has indicated that they could help out a lot, too, so hopefully we'll have it covered. Thanks again!
    ~Anne Troy

  6. #6
    I think i just indent because, like i said, i taught myself and no one taught me not to. It helps me separate commands. I'll remember that it's unpopular.

    Down, I'm aware of those form properties, so this answer was not what I was looking for. But thanks for trying.

    I have a new problem. Maybe I'll have better luck.

Posting Permissions

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