Bonhomme Septheure
Registered User.
- Local time
- Yesterday, 21:15
- Joined
- Apr 27, 2012
- Messages
- 14
Hi, this is the first question I've posted. If I'm not using the right forum, please let me know.
I've created a For Each loop in the before update event of a subform to check whether any text box in the detail section contains data. If at least one text box is not null or empty, the record is saved.
After I've used the database, triggered this event, closed the form, and closed the database, the .laccdb file remains. When I try to reopen the database, I get an error message saying it's locked. I have to then go into Task Manager, end the MSACCESS.EXE process, and delete the .laccdb file before I can open my database again.
This isn't a split database. It's on my computer and I'm the only user.
I'm posting my code below. This problem only started after I created and ran the code. If someone could look at this and tell me how this code is causing this problem and what to do about it, I'd be grateful. Thanks!
I've created a For Each loop in the before update event of a subform to check whether any text box in the detail section contains data. If at least one text box is not null or empty, the record is saved.
After I've used the database, triggered this event, closed the form, and closed the database, the .laccdb file remains. When I try to reopen the database, I get an error message saying it's locked. I have to then go into Task Manager, end the MSACCESS.EXE process, and delete the .laccdb file before I can open my database again.
This isn't a split database. It's on my computer and I'm the only user.
I'm posting my code below. This problem only started after I created and ran the code. If someone could look at this and tell me how this code is causing this problem and what to do about it, I'd be grateful. Thanks!
Code:
Private Sub Form_BeforeUpdate(Cancel As Integer)
If Me.NewRecord Then 'Test if this is a new record.
Dim ctl As Control
Dim i As Integer
i = 0
For Each ctl In Me.Section(0).Controls 'Loop through the controls in the detail section.
If ctl.ControlType = 109 Then 'Test each to see if it's a text box
If IsNull(ctl) = False Or Len(ctl) > 0 Then
Exit For 'bail out of the loop and continue with the record update.
End If
End If
i = i + 1
Next
If i = Me.Section(0).Controls.Count Then
Me.Undo
End If
End If
End Sub
Last edited: