Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coniditionally expand subdatasheet in form

Status
Not open for further replies.

jcfraun

Technical User
Dec 13, 2008
51
US
Assume I have a form (Form_x) with a subform (Form_x_subform). Both are in datasheet view. They are linked by Field_z. I only want the subform (i.e., subdatasheet) to expand automatically if it has data in it. If the subform is empty, I do not want it to expand.

How can I do this?
 
do you have the detail section set to can grow and can shrink yes?

Click the square box in the design view of the form in the top left corner, on the properties box, go to all and then on the form click on the Detal section.

You can set these values for the form header/footer and detail section.

I set that for most controls as well, but that doesn't have any effect in datasheet view.

misscrf

It is never too late to become what you could have been ~ George Eliot
 

In point of fact little in the way of conditionally formatting works in Datasheet View, it is what it is.

And Can Grow/Can Shrink, although it appears in Form Design View, doesn't work on forms, only on reports, unless something has changed since version 2003, and I've seen no reports of such.

The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
have you consider making it invisible if there are no subrecords? using the visible property may be a way to help accomplish some of what you want. Getting into setting dimensions based on the amount of records is always possible, but you would probably need to measure the form size based on every amount of records.

ie. if the record count is 1 then make the form this size, 2 that size and so on. Could get cumbersome if you have say 1,000 recs lol.

misscrf

It is never too late to become what you could have been ~ George Eliot
 
I believe everyone misread the OP's post.
The only way I know to do this is using sendkeys. I know of no property to expand a single record.

This will expand the current record if the current record has subrecords.

Here is an example
Code:
Private Sub Form_Current()
  ExpandRecord
End Sub

Public Sub ExpandRecord()
  'Collapse all records first
  Me.SubdatasheetExpanded = False
  'Set focus to a control
  Me.OrderID.SetFocus
  'Check to see if there are child records
  If hasRecords(Nz(Me.OrderID)) Then
    'expand current record
    SendKeys "+^{down}"
  End If
End Sub

Public Function hasRecords(OrderID As Long) As Boolean
  If Not DCount("orderID", "[Order Details]", "OrderID = " & OrderID) = 0 Then
     hasRecords = True
  End If
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top