NewRecord is a property of the form itself and I reference that in the Form_Current event.
NewRecord is a property of the form itself and I reference that in the Form_Current event.
The error when using my button to swap between data entry = true and data entry = false was just when I tried the code you suggested earlier, which has since been removed due to the errors. It was not what I was trying to fix.
I need the forms to not add any new records when making changes in "edit mode" (edit mode meaning DataEntry=False). If someone starts making changes while DataEntry=False, the form adds it as a new record instead of just editing the existing record. I want the form to either be:
DataEntry=True and the user is adding new records to the database
Or
DataEntry=False and the user is editing records in the database and cannot add any new records.
Also, clicking the record navigation at the bottom of the form as you said, does not produce any prompt. On top of that, it only navigates the records tied to the main form, not records in the subforms. To my understanding, it is not related to what I am trying to accomplish.
Sorry for the confusion
EDIT:
Just saw what you said about the NewRecord bit in the CurrentEvent. I was able to recreate the issue with the form adding new records while DataEntry = False with this code in place, so that doesn't fix the problem unfortunately
The code would only prevent new records in the main form.
This appears to be working properly, thank you for the help, it is very much appreciated.
In case anyone else is having this problem in the future, heres the code Gicu put in CurrentEvent:
Code:If Me.DataEntry = False Then If Me.NewRecord = True Then MsgBox "You cannot add a new record in lookup mode!", vbCritical, "New Record Detected" Me.Requery End If End If
If you want to implement it for the subforms simply change the Me.NewRecord to Me.Parent.Form.NewRecord and add it to the current event od each subform.
Cheers,
Vlad
Sorry, actually you want to check for
If Me.Parent.Form.DataEntry=False then
If Me.NewRecord = True then.....
You might need to tweak the code for the cases where there are no existing records and the subform goes automatically to a new record. You could add another test like If Me.recordset.recordcount=0 then ...
But you need to think this through, how would you deal with these cases?
I also noticed that some of the subforms are not limited to current AssetID (not master/child linking and no criteria in their recordsource), so you might also want to review that.
Example for code in subform:
Code:Code:Private Sub Form_Current() If Me.Parent.Form.DataEntry = False Then If Me.NewRecord = True Then MsgBox "You cannot add a new record in lookup mode!", vbCritical, "New Record Detected" Me.Requery End If End If End Sub
Cheers,
Vlad