Disallowing Edits Not Working (1 Viewer)

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
I have a Form that my team uses to enter test results. What I would like to have happen is once the results have been entered my team can go back and look at previous records but not be able to change them while still being able to add new records.

I've gone into the Form's properties and set Allow Deletions and Allow Edits to "No" but it doesn't seem to take. I can still edit previous records. I have made sure I saved the changes, closed and reopened the form, tried going back to "Yes" then switching back to "No" saving again, closing the form, closing the database.

I do have this code in the Form - could it be impacting the Edit properties?

Any advice will be appreciated!

Code:
Private Sub Form_Current()
  
     
If Me.cbxControlCard = -1 Then
Me.txtControlNumber.Visible = True
Else
Me.txtControlNumber.Visible = False
Me.txtControlNumber.Value = Null
End If

If Me.cboResult.Column(1) = "Fail" Then
Me.txtProblem.Visible = True
Else
Me.txtProblem.Visible = False
Me.txtProblem.Value = Null
End If
End Sub
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:56
Joined
Feb 19, 2002
Messages
43,477
You should toggle the AllowEdits setting in the Current event.

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

If Me.cboResult.Column(1) = "Fail" Then
    Me.txtProblem.Visible = True
Else
    Me.txtProblem.Visible = False
    Me.txtProblem.Value = Null
End If
End Sub
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
You should toggle the AllowEdits setting in the Current event.

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

If Me.cboResult.Column(1) = "Fail" Then
    Me.txtProblem.Visible = True
Else
    Me.txtProblem.Visible = False
    Me.txtProblem.Value = Null
End If
End Sub
I tried your code and it is still allowing edits on previous records. Any other ideas?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
I tried your code and it is still allowing edits on previous records. Any other ideas?
Really?
I just pasted
Code:
If Me.NewRecord = True Then
    Me.AllowEdits = True
Else
    Me.AllowEdits = False
End If
into one of my continuous forms and unable to edit previous records?
 

Josef P.

Well-known member
Local time
Today, 02:56
Joined
Feb 2, 2023
Messages
846
Me.txtControlNumber.Value = Null
This enables editing via the user interface, despite AllowEdit=False, if it is a bound control.
Fix: save the data record after changing the value.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:56
Joined
Feb 19, 2002
Messages
43,477
I tried your code and it is still allowing edits on previous records. Any other ideas?
You are don't something wrong. Post your code, including the procedure you posted it in.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:56
Joined
Feb 19, 2002
Messages
43,477
You can always modify the values using code regardless of the form property. @ashleymac Is that what you are talking about? Post YOUR code, all of it in the module.
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
I know that I'm doing something wrong. I just don't know what. Below is all the code that is on the Form in question, including the code Pat suggested earlier in this thread. I am very much a novice with VBA so I've been kind of piecing things together through Google and reading threads here. Thanks again for the help. I appreciate the insight.

My end goal is to make the most user friendly form I can for my team. I want them to be able to enter data and look back at complete records without running the risk of the accidently changing something.

Code:
Private Sub cboPartNumber_AfterUpdate()

    cboPartNumber.SetFocus

    Me.Description = cboPartNumber.Column(2)
'this will auto fill the description box after the part number is selected



End Sub



Private Sub cboQATeammember_GotFocus()

    Me.cboQATeammember.RowSource = "SELECT tblQATeam.ID, tblQATeam.Initials, tblQATeam.Status FROM tblQATeam WHERE (((tblQATeam.Status) = 'Active'))"

'When the combobox (dropdown) is selected it will only show Active teammembers

End Sub

Private Sub cboQATeammember_LostFocus()

    Me.cboQATeammember.RowSource = "SELECT tblQATeam.ID, tblQATeam.Initials FROM tblQATeam;"

'When the combobox is not selected inactive and active teammembers can be seen.  This will keep historical data correct

End Sub

Private Sub cboResult_AfterUpdate()

    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
    

End Sub

Private Sub cbxControlCard_AfterUpdate()

    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
    
End Sub

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
    
    'Keep the problem box hiddend on new records
    
End Sub

Private Sub DateTested_GotFocus()

    DoCmd.RunCommand acCmdShowDatePicker

    'this will auto show the datepicker when the cell is active


End Sub



Private Sub LastQADate_GotFocus()

    DoCmd.RunCommand acCmdShowDatePicker

End Sub
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
No idea why it does not work for you.
Can you upload your DB? or enough to see the issue.

Me.AllowEdits = Me.NewRecord would just be a shorter version.
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
No idea why it does not work for you.
Can you upload your DB? or enough to see the issue.

Me.AllowEdits = Me.NewRecord would just be a shorter version.
Do you need tables included or just the Forms?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
The forms will not work without the tables?
How are we supposed to test for a new record? :(
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 20:56
Joined
Feb 19, 2002
Messages
43,477
I just don't know what
So far you haven't put your problem in context. The code I posted works. However, if you want to lock the form IMMEDIATELY after a new record is saved, then you need to do that in the form's AfterUpdate event.

Me.AllowEdits = False

This locks the newly saved record so you can't change it while you are still looking at it. Not everyone wants this behavior so I don't always just do it.

Step by step - what are you doing when "it doesn't work"?
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
@Gasman realized that was a dumb question as soon as I asked it. DB attached.
 

Attachments

  • QA Team DB - For Help.accdb
    1.7 MB · Views: 23

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
Seriously, what are the logon credentials? :(
Plus, how are we meant to recreate the issue?
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
Seriously, what are the logon credentials? :(
My apologies. When I'm looking at the code and such I just right click on the login screen and close it.

You can use username: doejane pw: dog

The specific form I'm having issues with is "frmRecordKeeping"

You can get to it after the login screen Forms > Results

Again I apologize for the missing information.
 

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
So far you haven't put your problem in context. The code I posted works. However, if you want to lock the form IMMEDIATELY after a new record is saved, then you need to do that in the form's AfterUpdate event.

Me.AllowEdits = False

This locks the newly saved record so you can't change it while you are still looking at it. Not everyone wants this behavior so I don't always just do it.

Step by step - what are you doing when "it doesn't work"?
I copied and pasted your original code exactly how you put it in your response. I saved it. Closed the VBA screen. That look me back to my form in Design View. I saved my form for good measure and closed the form.

Then I re-opened the form. Clicked on a text box located in the first record, which is a completed record not a new record, to see if it would let me type in the box or delete from the text box to try and recreate an accidental edit, which is what I'm trying to avoid, and the form accepted the delete and the random typing I did.

To me this is editing the form which is what I'm trying to avoid. If I'm using the wrong verbiage I apologize.
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
Well if it is FormRecordKeeping, you have me flummoxed. :(
I am walking the code and you are correct, the edits is not working. I can only assume the form is corrupt?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
OK, I can only amend records 1 and 3 not 2 & 4 in Notes and other controls?
Able to add records 5 and 6 and can amend each of those?

SO not a clue as to what is going on, sorry.

It appears form is corrupt. Created a new form based on that table and it works as expected.
 
Last edited:

ashleymac

New member
Local time
Yesterday, 19:56
Joined
Apr 4, 2024
Messages
19
OK, I can only amend records 1 and 3 not 2 & 4 in Notes and other controls?
Do you know if there is a setting I could have accidentally hit that makes alternate odd/even records some how?

Or would it have more to do with 1 & 3 being Pass in the Results combobox and 2&4 being Fail?
 

Gasman

Enthusiastic Amateur
Local time
Today, 01:56
Joined
Sep 21, 2011
Messages
14,445
Not unless you coded for that, and I cannot see any evidence of that.
Besides I added 5 and 6 with pass and a fail, so that would not be it.
I reckon it is corrupt.
Create a simple form based on that table just to test (which is what I did).
Add
Me.AllowEdits = Me.NewRecord in the current event.
in the current event.
Then test that out. Works as it should for me.
 

Users who are viewing this thread

Top Bottom