Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94

    Command button to allow edits not working ??????

    I have a form which is primarily used is to add new records – not edit the records. Therefore, On the form properties I have AllowEdits = No.
    However, there are times in which it is necessary to edit a record. Therefore, I have a button on the form which on click event should allow edits. The code is below

    Code:
    Private Sub cobEdit_Click()
         If MsgBox("If you change the name it will change all History.  Better to create a new account", vbYesNo, "1st Edit Confirmation") = vbYes Then
            If MsgBox("Are you SURE you want to EDIT?" & vbCrLf & _
                "I STRONGLY suggest a new account.", vbYesNo, "2nd EDIT Confirmation") = vbYes Then
         
       AllowEdits = True
          End If
            End If  
    
    
    End Sub
    
    


    After clicking a button I still cannot edit an item. What am I doing wrong?

    Last edited by TenOc; 12-08-2021 at 07:01 PM.

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    1,611
    Prefix the property with Me. ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,947
    Check this property:
    If form property DATA ENTRY is Yes, then the form is restricted to entering new records only.

  4. #4
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    10,143
    What's missing from the info is how the form is being opened. If the data mode is being set via code, this can over-ride form properties. You may have to tweak AllowAdditions, DataEntry and AllowEdits all at once when switching options. Another way might be to open the form as DataEntry at first, then switch the mode. While that doesn't determine if records can be edited (edits could be done via code), from a user standpoint it should appear that way because all they'll see is a blank record for adding.

    Was that a manual attempt to wrap the code in code tags? Closing bracket is missing, so that should explain it.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by Welshgasman View Post
    Prefix the property with Me. ?
    Adding me. did not help

  6. #6
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by davegri View Post
    Check this property:
    If form property DATA ENTRY is Yes, then the form is restricted to entering new records only.
    DataEntry is NO

  7. #7
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by Micron View Post
    What's missing from the info is how the form is being opened. .
    The form is open by a command Button on the "Start" form.


    Also thanks for the ] hint

  8. #8
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    10,143
    The form is open by a command Button on the "Start" form.
    Well, that's a start, but it's only a wee morsel. I guess you should post the code that opens the form so we can see if you're using the DataMode parameter since you didn't address that.
    If the data mode is being set via code...
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  9. #9
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by Micron View Post
    Well, that's a start, but it's only a wee morsel. I guess you should post the code that opens the form so we can see if you're using the DataMode parameter since you didn't address that.

    See screen shot below


    Click image for larger version. 

Name:	Open Form 2021-12-08_22h26_00.png 
Views:	13 
Size:	18.9 KB 
ID:	46857

  10. #10
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,947
    After clicking a button I still cannot edit an item. What am I doing wrong?
    What exactly does this mean?

    You can see records and when you try to change a value, you get a beep?
    You cannot see any records at all?
    You get some error message? If so, it would be helpful for us to know.
    If error message, what exactly do you do that causes it?

  11. #11
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    Quote Originally Posted by davegri View Post
    What exactly does this mean?

    You can see records and when you try to change a value, you get a beep?
    You cannot see any records at all?
    You get some error message? If so, it would be helpful for us to know.
    If error message, what exactly do you do that causes it?
    I see all the records And all fields.
    I do not get an error message
    There is no beep
    I cannot change any field in an existing record because no field will allow me to click on it that is I cannot have it get focus. I'm a newbie so excuse me if I did not describe this correctly.
    I can add a new record, but once added (I move off the record so it is automatically saved) I cannot change any information in a field of the new record.

  12. #12
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,947
    Quote Originally Posted by TenOc View Post
    I see all the records And all fields.
    I do not get an error message
    There is no beep
    I cannot change any field in an existing record because no field will allow me to click on it that is I cannot have it get focus. I'm a newbie so excuse me if I did not describe this correctly.
    I can add a new record, but once added (I move off the record so it is automatically saved) I cannot change any information in a field of the new record.
    Just to narrow it down, if in design mode you change the form property ALLOW EDITS = YES, can you now edit a record?
    If not, then go back to design mode and look at a textbox property, Data tab. Is the textbox locked or disabled?

    If not, then there appears to be code that you are not aware of that is restoring ALLOW EDITS = NO in one of your form events.

  13. #13
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    10,143
    If the latest posts don't help, consider copying, compact/repair the copy, zip and post here for analysis. I see from the pic that you're using a macro; AFAIK, not setting this parameter in the macro allows the property sheet settings to take precedence so I suspect that's where the problem lies. I considered that there might be an underlying query for the form which is not updatable, but I don't think you can add records to such a query.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    TenOc is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Feb 2015
    Posts
    94
    I think I have found the problem

    Form on Current Event. When I commented the "acNewRec" it works.

    Code:
    Private Sub Form_Current()
    DoCmd.SetWarnings False
    'DoCmd.GoToRecord , , acNewRec
    End Sub
    Now the question is how to have the NEW to be added record to have the focus when the form opens?????

  15. #15
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    1,611
    Quote Originally Posted by TenOc View Post
    I think I have found the problem

    Form on Current Event. When I commented the "acNewRec" it works.

    Code:
    Private Sub Form_Current()
    DoCmd.SetWarnings False
    'DoCmd.GoToRecord , , acNewRec
    End Sub
    Now the question is how to have the NEW to be added record to have the focus when the form opens?????
    Put it in the form load event.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?search_query=debug+access+vba



Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Command Button On Subform not working
    By aamer in forum Access
    Replies: 2
    Last Post: 12-21-2019, 05:57 PM
  2. Replies: 3
    Last Post: 03-15-2019, 06:05 PM
  3. Replies: 13
    Last Post: 01-22-2015, 05:27 PM
  4. command button for allow edits
    By phineas629 in forum Forms
    Replies: 1
    Last Post: 10-18-2011, 07:09 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums