On Current Code - Run in Form View Only

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?
 
J

JohnWL

Try this: Look at the properties for the form itself, and
set Allow Datasheet View to No.

John Loewen
 
B

Bruce M. Thompson

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
'***
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top