On Current Code - Run in Form View Only

  • Thread starter Thread starter Dave Evans
  • Start date Start date
D

Dave Evans

I have some code that hides the my subforms if there are no records within
that subform

Private Sub Form_Current()
With Me![SubFormName].Form
.Visible = (.RecordsetClone.RecordCount > 0)
End With
End Sub

However when the form is switched to datasheet view it comes up with an
error message.

Is there a way to get this code to run in Form View Only?
 
Try this: Look at the properties for the form itself, and
set Allow Datasheet View to No.

John Loewen
 
I have some code that hides the my subforms if there are no records within
that subform

Private Sub Form_Current()
With Me![SubFormName].Form
.Visible = (.RecordsetClone.RecordCount > 0)
End With
End Sub

However when the form is switched to datasheet view it comes up with an
error message.

Is there a way to get this code to run in Form View Only?

Yes. Try the following modifications:

'***
Private Sub Form_Current()
'Constant for "Current View" property
Const conFormView = 1 'Form View

With Me![SubFormName].Form
If Me.CurrentView = conFormView Then 'If in Form view
.Visible = (.RecordsetClone.RecordCount > 0)
End If
End With
End Sub
'***
 
Back
Top