Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858

    Try
    Code:
    If NOT Me.NewRecord then
        Me.AllowEdits = (Datum = Date)
    End If
    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?sear...bug+access+vba

  2. #17
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Quote Originally Posted by Welshgasman View Post
    Try
    Code:
    If NOT Me.NewRecord then
        Me.AllowEdits = (Datum = Date)
    End If
    Works perfectly, thank you.

    EDIT: It works on every form except one and I don't know why.
    It returns this error when I enter the form view.

    Click image for larger version. 

Name:	error.JPG 
Views:	19 
Size:	26.0 KB 
ID:	43646

    That form is also very slowly loading and it is very important to me, I can't just ignore it.
    Do you have advice to help me fix it?

    Access recommends fewer controls

  3. #18
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,858
    Possibly a corrupt form, if other forms are OK. Try a decompile and compile again.
    Try a new DB and import enough to test just that form. Then if good, import everything else.
    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?sear...bug+access+vba

  4. #19
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Hello again guys, I just have one question about this code and locking the old records.
    We are using it over a month and it works fine, but here is the small problem we've noticed:
    When you try to navigate through previous records in the form view, it locks all the old records (like it's supposed to), but when you go back to the today's date, record is also locked for editing in form view
    It can be undone with reopening the form, but can it be fixed somehow in the lines of the code?

    This is the code in the form's "On current"
    Code:
    Option Compare Database
    Option Explicit
    
    
    Private Sub Form_Current()
    
    
    If Me!Datum < Now() - 1 Then
    
    
    Me.AllowEdits = False
    
    
    End If
    End Sub

  5. #20
    Join Date
    Apr 2017
    Posts
    1,673
    You did'nt estimate, what happens when condition is false! And you can drop If...End If entirely
    ...
    Me.AllowEdits = (Me!Datum > Now()-1)
    ...

    Or in case you don't want yesterdays entries which are less than 24 hours old (only when field Datum contains time part) to be editable
    ...
    Me.AllowEdits = (Me!Datum >= Date())
    ...

  6. #21
    santon's Avatar
    santon is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2020
    Posts
    44
    Works perfectly, thanks!

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

Similar Threads

  1. Lock a query for editing - run only
    By paul83 in forum Queries
    Replies: 3
    Last Post: 06-14-2016, 10:30 AM
  2. How to temporary lock form for editing
    By aonsu209 in forum Forms
    Replies: 5
    Last Post: 01-15-2015, 07:59 AM
  3. Editing Visio drawing in Form view
    By jmejorada360 in forum Import/Export Data
    Replies: 2
    Last Post: 08-10-2012, 10:15 AM
  4. lock the editing of combobox text
    By Grooz13 in forum Forms
    Replies: 14
    Last Post: 10-23-2011, 02:08 PM
  5. Replies: 0
    Last Post: 03-26-2007, 12:24 AM

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