Hide subform (1 Viewer)

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
Hi all,

I have a sub form that must be visible only when a control has a certain value
and the sub form must only be visible if there is any records to display if it meets the control conditions

DAWSheetCSOrderStock only to be visible if it contains records

not sure how to code VBA.

Code Tags Added by UG
Please use Code Tags when posting VBA Code
Please feel free to Remove this Comment
https://www.access-programmers.co.u...e-use-code-tags-when-posting-vba-code.240420/

Code:
My Code: #
If Me.Type = "SB" Or (Me.Type = "Quality") Or (Me.Type = "Standard") Then
Me.Warranty.Visible = False
Me.DAWSheetCSOrderStock.Visible = True
Else
Me.Warranty.Visible = True
Me.DAWSheetCSOrderStock.Visible = False
End If#
 
Last edited by a moderator:

cheekybuddha

AWF VIP
Local time
Today, 09:42
Joined
Jul 21, 2014
Messages
2,274
Does your code not work? What happens instead?

You could write the code like:
Code:
  Dim blShow As Boolean

  With Me
    blShow = .Type = "SB" Or .Type = "Quality" Or .Type = "Standard"
    .Warranty.Visible = Not blShow
    .DAWSheetCSOrderStock.Visible = blShow
  End With

You will need this code in your from's Current event if you wish it to update as you change records
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:42
Joined
May 7, 2009
Messages
19,230
Better to disable the subform, instead of having a Hole when the subform got hidden.
 

bob fitz

AWF VIP
Local time
Today, 09:42
Joined
May 23, 2011
Messages
4,719
Does your code not work? What happens instead?

You could write the code like:
Code:
  Dim blShow As Boolean

  With Me
    blShow = .Type = "SB" Or .Type = "Quality" Or .Type = "Standard"
    .Warranty.Visible = Not blShow
    .DAWSheetCSOrderStock.Visible = blShow
  End With

You will need this code in your from's Current event if you wish it to update as you change records
Might need it in the After Update event of the control called "Type" as well
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
my code works, i just dont know how to code the sub form to be hidden when on records with the above criteria to be hidden if it does not meet the criteia
 

Dreamweaver

Well-known member
Local time
Today, 09:42
Joined
Nov 28, 2005
Messages
2,466
What I do sometimes is add the subform to a footer section then Hide that then use then run the sizetofitform.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:42
Joined
May 7, 2009
Messages
19,230
Hide or Disable it on the Forms current event and on the forms afterupdate event.
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
What happens when your code runs
the subform is hidden when it does not meet the criteria of the control, works fine
but it also needs to be hidden if no Data
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
Hide or Disable it on the Forms current event and on the forms afterupdate event.
no input required on this form, it is a status of the record which needs to be approved
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
Does your code not work? What happens instead?

You could write the code like:
Code:
  Dim blShow As Boolean

  With Me
    blShow = .Type = "SB" Or .Type = "Quality" Or .Type = "Standard"
    .Warranty.Visible = Not blShow
    .DAWSheetCSOrderStock.Visible = blShow
  End With

You will need this code in your from's Current event if you wish it to update as you change records
I tried your code, it still displays the sub form with no data
 

bob fitz

AWF VIP
Local time
Today, 09:42
Joined
May 23, 2011
Messages
4,719
Use

if Me.SubformControlName.Form.RecordsetClone.RecordCount >0 then

To test for Records in subform
 

cheekybuddha

AWF VIP
Local time
Today, 09:42
Joined
Jul 21, 2014
Messages
2,274
I tried your code, it still displays the sub form with no data
Oops! missed that part of the requirement!

Bake in Bob Fitz's suggestion:
Code:
' ...
    blShow = .Type = "SB" Or .Type = "Quality" Or .Type = "Standard" Or .SubformControlName.Form.RecordsetClone.RecordCount = 0
' ...

hth,

d
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
Oops! missed that part of the requirement!

Bake in Bob Fitz's suggestion:
Code:
' ...
    blShow = .Type = "SB" Or .Type = "Quality" Or .Type = "Standard" Or .SubformControlName.Form.RecordsetClone.RecordCount = 0
' ...

hth,

d
I understand the code you provided but the form is still being displayed with no records
 

cheekybuddha

AWF VIP
Local time
Today, 09:42
Joined
Jul 21, 2014
Messages
2,274
Sorry, not enough coffee!

Try:
Code:
' ...
    blShow = (.Type = "SB" Or .Type = "Quality" Or .Type = "Standard") And .SubformControlName.Form.RecordsetClone.RecordCount > 0
' ...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 16:42
Joined
May 7, 2009
Messages
19,230
Code:
Private Sub Form_Current()
Call fncHideSub
End Sub

Private Sub Form_AfterUpdate()
Call fncHideSub
End Sub


Public Function fncHideSub()
    If Me.DAWSheetCSOrderStock.Form.Recordset.RecordCount < 1 Then
        Me.Warranty.Visible = True
        Me.DAWSheetCSOrderStock.Visible = False
    Else
        If Me.Type = "SB" Or (Me.Type = "Quality") Or (Me.Type = "Standard") Then
            Me.Warranty.Visible = False
            Me.DAWSheetCSOrderStock.Visible = True
        Else
            Me.Warranty.Visible = True
            Me.DAWSheetCSOrderStock.Visible = False
        End If
    End If
End Function
 

Gismo

Registered User.
Local time
Today, 11:42
Joined
Jun 12, 2017
Messages
1,298
Code:
Private Sub Form_Current()
Call fncHideSub
End Sub

Private Sub Form_AfterUpdate()
Call fncHideSub
End Sub


Public Function fncHideSub()
    If Me.DAWSheetCSOrderStock.Form.Recordset.RecordCount < 1 Then
        Me.Warranty.Visible = True
        Me.DAWSheetCSOrderStock.Visible = False
    Else
        If Me.Type = "SB" Or (Me.Type = "Quality") Or (Me.Type = "Standard") Then
            Me.Warranty.Visible = False
            Me.DAWSheetCSOrderStock.Visible = True
        Else
            Me.Warranty.Visible = True
            Me.DAWSheetCSOrderStock.Visible = False
        End If
    End If
End Function
Thank you
Works perfect
 

Users who are viewing this thread

Top Bottom