T
Tony Vrolyk
I am trying to refer to a subform from a module and want to check if it is
empty. The subform has the following properties
AllowFitlers = No
AllowEdits = Yes
AllowDeletions = No
AllowAdditions = No
DataEntry = No
New records and record deletions are handled by shortcut menus. Of course if
there is no record I don't want the delete option to do anything at all. For
instance I use the code below to delete a record. However the "If IsNull..."
statement always resolves to True even when no records are displayed. I then
get a Run-time error "2427 - You entered an expresion that has no value". I
could use error handling to handle Error 2427 but I would prefer that no
prompt occur when there is no record.
For some reason I think this should be easy but it is eluding me
Thanks
Tony
**code start**
Function fPlans_Delete()
Dim db As DAO.Database, rst As Recordset
If Not IsNull(Forms!Clients!Subform.Form!PlanIDNumber) Then
If MsgBox("Permanently Delete Plan?", vbQuestion + vbYesNo +
vbDefaultButton1, "Confirm") = vbNo Then
DoCmd.CancelEvent
Else
Set db = CurrentDb
Set rst = db.OpenRecordset("Plans", dbOpenDynaset)
rst.FindFirst "[PlanIDNumber] ='" &
Forms!Clients.Subform!PlanIDNumber & "'"
If rst.NoMatch Then
MsgBox "No match found", vbOKOnly
Else
rst.Delete
End If
rst.Close
Forms!Clients!Subform.Requery
End If
End If
End Function
**code end**
empty. The subform has the following properties
AllowFitlers = No
AllowEdits = Yes
AllowDeletions = No
AllowAdditions = No
DataEntry = No
New records and record deletions are handled by shortcut menus. Of course if
there is no record I don't want the delete option to do anything at all. For
instance I use the code below to delete a record. However the "If IsNull..."
statement always resolves to True even when no records are displayed. I then
get a Run-time error "2427 - You entered an expresion that has no value". I
could use error handling to handle Error 2427 but I would prefer that no
prompt occur when there is no record.
For some reason I think this should be easy but it is eluding me
Thanks
Tony
**code start**
Function fPlans_Delete()
Dim db As DAO.Database, rst As Recordset
If Not IsNull(Forms!Clients!Subform.Form!PlanIDNumber) Then
If MsgBox("Permanently Delete Plan?", vbQuestion + vbYesNo +
vbDefaultButton1, "Confirm") = vbNo Then
DoCmd.CancelEvent
Else
Set db = CurrentDb
Set rst = db.OpenRecordset("Plans", dbOpenDynaset)
rst.FindFirst "[PlanIDNumber] ='" &
Forms!Clients.Subform!PlanIDNumber & "'"
If rst.NoMatch Then
MsgBox "No match found", vbOKOnly
Else
rst.Delete
End If
rst.Close
Forms!Clients!Subform.Requery
End If
End If
End Function
**code end**