Disallowing Edits Not Working (1 Viewer)

LarryE

Active member
Local time
Today, 08:07
Joined
Aug 18, 2021
Messages
606
What happens if a user enters and saves wrong information into your tables? Do you just let it go forever with no way of correcting it? I am a little surprised no one has told you this is a really really bad idea. That said, you might need to open the form in design mode first, then change the Allow Edits property with code, save the form and then re-open it.

Also, if you change the forms Allow Edits property to No, no one can add new records to any subform(s), if they exit, because subforms are controls and no control can be changed.

For the record, this is a bad idea.
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
What happens if a user enters and saves wrong information into your tables? Do you just let it go forever with no way of correcting it? I am a little surprised no one has told you this is a really really bad idea. That said, you might need to open the form in design mode first, then change the Allow Edits property with code, save the form and then re-open it.

Also, if you change the forms Allow Edits property to No, no one can add new records to any subform(s), if they exit, because subforms are controls and no control can be changed.

For the record, this is a bad idea.
I have an admin form (that certain members of my team can access) that will allow edits to fix any mistakes that happen or fix missed types. I wouldn't just leave incorrect data without it being corrected.
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
@Gasman Thanks for your help on this. I tried making just a simple form and it does seem to work. So I'll try remaking the form from the ground up and hope that works.

Hopefully I can keep the same type of formatting and functionality as the original. :)
 

Josef P.

Well-known member
Local time
Today, 17:07
Joined
Feb 2, 2023
Messages
847
Code:
Private Sub Form_Current()

    If Me.NewRecord = True Then
        Me.AllowEdits = True
    Else
        Me.AllowEdits = False
    End If
       

    If Me.cbxControlCard = -1 Then
        Me.txtControlNumber.Visible = True
    Else
        Me.txtControlNumber.Visible = False
        Me.txtControlNumber.Value = Null
    End If
   
    'Keep the new control number box hidden on new records
   
    If Me.cboResult.Column(1) = "Fail" Then
        Me.txtProblem.Visible = True
    Else
        Me.txtProblem.Visible = False
        Me.txtProblem.Value = Null
    End If
   
'---------------
' Fix:
' Record is "Dirty" => User can edit data
    If Me.Dirty Then
      Me.Dirty = False
    End If
'-----------------------

    'Keep the problem box hiddend on new records
   
End Sub
Note:
When solving the problem, I did not question why an existing data record always has to be changed.
If this is not necessary, the problem would not occur and would not need to be fixed.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:07
Joined
Sep 21, 2011
Messages
14,466
You could try exporting the form and reimporting it, not something I have done, and when I just tried now I get

1712864138209.png

I tried removing Fom_ in filename and the entry in the file, with not success. It ended up coming in the module classes, so an expert is going to have to help with any export/import method.
 

LarryE

Active member
Local time
Today, 08:07
Joined
Aug 18, 2021
Messages
606
I have an admin form (that certain members of my team can access) that will allow edits to fix any mistakes that happen or fix missed types. I wouldn't just leave incorrect data without it being corrected.
So every single entry in every single record is checked for accuracy. And if someone enters a 5 instead of a 6 then the error is caught. Why not just let the original entry user correct their own entry mistakes as they work? They are the ones who know what the data entry should be from the start.

OK it's your application, not mine.
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
@Josef P. That seemed to do the trick! Thank you!!

If you don't mind - can you tell me why that fixed the problem incase I run into something similar in the future?
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:07
Joined
Sep 21, 2011
Messages
14,466
So why did a brand new form work as expected?
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
Spoke too soon. Now I'm getting this error. I should note that I do have all the various fields set to Required at a table level to ensure my data entry guys can't skip out on adding vital information.

Will this interfere with the .Dirty VBA?

1712871890287.png
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:07
Joined
Sep 21, 2011
Messages
14,466
Yes, I got all that with my new form, just entering the little I needed to get it saved.. You are dirtying the record with that, before being able to enter the data. :)

TBH I think that dirty is a workaround, but I would not trust what appears to be a corrupt form, so would recreate myself.
I was thinking however, I used to store CreatedBy, CreatedDate,AmendedBy,AmendedDate in some tables in one particular DB.

You could do the same, at least for dates/times and allow perhaps 1 hour from creation to amend before you lock them as you are doing now.?

Just a thought.
 

Josef P.

Well-known member
Local time
Today, 17:07
Joined
Feb 2, 2023
Messages
847
If you don't mind - can you tell me why that fixed the problem incase I run into something similar in the future?
If a data record ist edit by VBA and not saved - see edit symbol (pensil) - Form.Dirty is True and the user can edit the data in this record.
This is the behaviour of Access. You would have to ask the Access programmers why this is the case ;)
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:07
Joined
Feb 19, 2002
Messages
43,492
In the Current event, the record should never be dirty.
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
So I've been recreating the form as @Gasman suggested and testing step by step.

This code suggested by @Pat Hartman yesterday works as expected (saved records can't be accidentally edited but new records can be created)....
Code:
Private Sub Form_Current()

    If Me.NewRecord = True Then
        Me.AllowEdits = True
    Else
        Me.AllowEdits = False
    End If
 
End Sub

Unit I added the below code to Form_Current. The below code is meant to keep certain things hidden on new records until a selection is made. Is there a way to change the below so it isn't some how negating the above?

Code:
If Me.cboResult.Column(1) = "Fail" Then
        Me.txtProblem.Visible = True
    Else
        Me.txtProblem.Visible = False
        Me.txtProblem.Value = Null
    End If
    
    'Bring up the "Problem" box when an item has failed inspection
    
     If Me.cbxControlCard = -1 Then
        Me.txtControlNumber.Visible = True
    Else
        Me.txtControlNumber.Visible = False
        Me.txtControlNumber.Value = Null
    End If
    
    'Show the control number box if a new control number was made
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:07
Joined
Feb 19, 2002
Messages
43,492
Stop setting the value. YOU are dirting the record. Set the default at the table to be null and leave it at that.
 

ashleymac

New member
Local time
Today, 10:07
Joined
Apr 4, 2024
Messages
19
Pat - Thank you! That actually made sense to me and better yet it seems to have worked!

I appreciate everyone's help and time.

Have a great day! :)
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:07
Joined
Sep 21, 2011
Messages
14,466
From this thread https://www.access-programmers.co.u...ing-a-form-as-text-and-then-importing.330853/ I have been shown how to save and import Forms as text, which I was hoping would remove any corruption?
You might want to try that sometime. Could save you a lot of time reformatting the form?

Code:
Application.SaveAsText acForm, "frmName", "C:\path\to\file.txt"

' and

Application.LoadFromText acForm, "frmName", "C:\path\to\file.txt"

Thanks to @cheekybuddha for that information.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:07
Joined
Feb 19, 2002
Messages
43,492
Please look at the code in the thread and understand WHY i named the exported objects with specific suffixes.

I also have a database which has a lot of the code attached to forms. I didn't post the db because it is currently in flux and I haven't had a chance to fix what I broke.
 

Gasman

Enthusiastic Amateur
Local time
Today, 16:07
Joined
Sep 21, 2011
Messages
14,466
Please look at the code in the thread and understand WHY i named the exported objects with specific suffixes.

I also have a database which has a lot of the code attached to forms. I didn't post the db because it is currently in flux and I haven't had a chance to fix what I broke.
Pat, what code are we talking about re export, as I cannot see any in this thread from yourself?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 11:07
Joined
Feb 19, 2002
Messages
43,492
Maybe it was in a different thread yesterday. I didn't see two threads that were talking about exporting to text so I thought it was the same thread.
 

Users who are viewing this thread

Top Bottom