Why not set the form's property "Allow Additions" to No?Hi, I'm using code to go to the next record and warn that i'm on the last record so it doesn't proceed to a new record.
..
Why not set the form's property "Allow Additions" to No?Hi, I'm using code to go to the next record and warn that i'm on the last record so it doesn't proceed to a new record.
..
The bad records were entered because you did not properly control validation, NOT because you did not control scrolling.and 9 false/blank records (entered by accident before preventing the navigation buttons going past the last record)
If Me.txtField1 & "" = "" Then
Msgbox "Field 1 is required. Please enter a valid value.",vbOKOnly
Cancel = True
Me.txtField1.SetFocus
Exit Sub
End If
If Me.cboField2 & "" = "" Then
Msgbox "Field 2 is required."vbOKOnly
Cancel = True
Me.cboField2.SetFocus
Exit Sub
End If
....
Why not set the form's property "Allow Additions" to No?
The bad records were entered because you did not properly control validation, NOT because you did not control scrolling.
In the BeforeUpdate event of the form, one of the things you might want to consider doing (especially if you don't have required fields set to required in the table) is to ensure that all required fields have a valid value. If they don't, you would cancel the update to PREVENT the recording from being added or updated.
Code:If Me.txtField1 & "" = "" Then Msgbox "Field 1 is required. Please enter a valid value.",vbOKOnly Cancel = True Me.txtField1.SetFocus Exit Sub End If If Me.cboField2 & "" = "" Then Msgbox "Field 2 is required."vbOKOnly Cancel = True Me.cboField2.SetFocus Exit Sub End If ....
You could just set the property on form load depending on the user?
Me.AllowAdditions = False
Me.AllowEdits = False
No need for an extra form, you can change it by code.It's the main data entry and view form. It would mean duplicating the form exactly and use one to view and one to edit and/or enter records. ...
No need for an extra form, you can change it by code.
You must already have some criteria, when it is allowed to add a new record, (when you write "It's the main data entry form"), so here would be the right place for Me.AllowAdditions = True.
As the database is mainly for me to use I want it to work my way. If others don't like my way then so be it, they won't use it.
I won't bother you anymore.![]()
![]()
That's fine, but I have to ask, why bother posting this thread if you are just going to ignore the simple advice given by others including JHB & Pat Hartman?