SUBFORM CONTROLS (1 Viewer)

euphonium01

Registered User.
Local time
Today, 05:59
Joined
Nov 17, 2018
Messages
17
I have a database I did that lists Electrical connections, Modules, Fuses etc for an old Jaguar. I have a Form, ConnectorsF, that lists all the connectors on the vehicle and a Subform, ConnectorPinsSF, that lists how many pins/wires are in that Connector. Sometimes, there's only 1 pin/wire, others can be up to 50 or so.

The Subform has navigation buttons I created to advance through each pin/wire. What I need is for the navigation buttons to disappear if there's less than 1 pin/wire, and reappear when there's more than 1. The Subform has a counter control, PINCOUNT.

How do I get the Navigation Buttons on the Subform to disappear/appear. I am very new to VBA, so please help it be simple... I have an Event Procedure attached to the Subform's OnCurrent Event -
If Me.PINCOUNT > 1 Then
Me.First Record.Visible = True
Else: Me.FirstRecord.Visible=False
End If

The NextRecord, PreviousRecord etc were done the same, but none of it works.

I realise this is probably very simple, but its not to me... can anyone help please?
Paul
 
Are you able to post a sample db with test data? Are we talking about the built-in navigation buttons or something you created? To see how many records are in the subform, you can check its RecordCount property.

Sent from phone...
 
I’m a bit afraid to ask but could you share the relationship of the connections database?
 
you may try this on the subform's Current Event:
Code:
Private Sub Form_Current()
Dim bolVisible As Boolean
With Me
    bolVisible = (.Recordset.RecordCount > 1)
    !FirstRecord.Visible = bolVisible
    !NextRecord.Visible = bolVisible
    !PrevousRecord.Visible = bolVisible
    !LastRecord.Visible = bolVisible
End With
End Sub
 
...or...
Code:
Private Property Get Buttons() As Access.CommandButton()
    Buttons = Array(Me.cmdFirst, Me.cmdPrev, Me.cmdNext, Me.cmdLast)
End Property

Private Sub Form_Current()
    SetVisibility Buttons, Me.Recordset.RecordCount > 1
End Sub

' in a library somewhere, not on the form
Public Sub SetVisibility(vEnumerable, State As Boolean)
    Dim obj As Object
    For Each obj In vEnumerable
        obj.Visible = State
    Next
End Sub
 
Hi all, many thanks for the replies so far, I intend trying these out tomorrow. For the moment, a few have asked questions.
I think the answer to the question on relationship between ConnectorsF and ConnectorPinsSF is it is a One to Many
The Subform buttons are those I created using VBA, I don't usually use the built-in Navigation Buttons
If there is just the one record in the Subform, this is the reason I want the created navigation buttons to disappear.. if there's only one record there then the created navigation buttos arent needed.
If the suggestions above don't work I will try and suss out how to post samples
Hope this answers the questions so far?

So many thanks for these replies,,,
Paul
 
Just a little bit more about the relationships question. All the Connectors have a designation such as CA1, or CA2, BB10 etc. The Connector PINs would be CA1-1, CA1-2 etc, or BB10-1 etc depending on the amount of pins there are in the connector.
Untitled.jpg
 
Last edited:

Users who are viewing this thread

Back
Top Bottom