form (1 Viewer)

njd

Registered User.
Local time
Today, 15:16
Joined
Jul 5, 2019
Messages
10
Good Day,



firstly, I would like thank you for your help and I learned a lot from it.

last week you helped me with code about replacing the checkbox labels and it is working.
However, is there a way to replace the textbox?
I mean if one cell is empty no need to show the textbox of it and make the next one in its place.
i tried by modifying the previous code but it did not work.

Your help is really appreciated.
Thank you in advance.

first, question, is LA, NY, LND the control source ( field name) of your checkboxes?
if so you need to code your Form's Current event.
before that, you need to adjust the width of your labels (wider than LND label).
next, you also need to rename all your controls.
for labels, rename them in sequence (from left to right) as lblChk1, lblChk2, lblChk3.
same with your checkboxes. starting from Left Chk1, Chk2, Chk3.
Code:
Private Sub Form_Current()
    
    Dim i As Integer
    Dim aLabel() As String
    Dim aControlSource() As String
    
    ReDim aLabel(0)
    ReDim aControlSource(0)
    
    On Error Resume Next
    
    With Me
    
        ' hide all labels and checkboxes
        .lblChk1.Visible = False
        .lblChk2.Visible = False
        .lblChk3.Visible = False
        
        .chk1.Visible = False
        .chk2.Visible = False
        .chk3.Visible = False
        
        If Nz([LA], False) = True Then
            ReDim Preserve aLabel(UBound(aLabel) + 1)
            ReDim Preserve aControlSource(UBound(aControlSource) + 1)
            aLabel(UBound(aLabel)) = "LA"
            aControlSource(UBound(aControlSource)) = "LA" 'should be replaced with correct fieldname"
        End If
        If Nz([NY], False) = True Then
            ReDim Preserve aLabel(UBound(aLabel) + 1)
            ReDim Preserve aControlSource(UBound(aControlSource) + 1)
            aLabel(UBound(aLabel)) = "NY"
            aControlSource(UBound(aControlSource)) = "NY" 'should be replaced with correct fieldname"
        End If
        If Nz([LND], False) = True Then
            ReDim Preserve aLabel(UBound(aLabel) + 1)
            ReDim Preserve aControlSource(UBound(aControlSource) + 1)
            aLabel(UBound(aLabel)) = "LND"
            aControlSource(UBound(aControlSource)) = "LND" 'should be replaced with correct fieldname"
        End If
        
        ' show the labels and control if there is
        For i = 1 To UBound(aLabel)
            .Controls("lblchk" & i).Caption = aLabel(i)
            .Controls("chk" & i).ControlSource = aControlSource(i)
            
            ' make them visible
            .Controls("lblchk" & i).Visible = True
            .Controls("chk" & i).Visible = True
            
        Next
    End With
    
End Sub
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:16
Joined
May 7, 2009
Messages
19,227
here is a sample for your textbox.
 

Attachments

  • textbox.zip
    22.9 KB · Views: 26

Users who are viewing this thread

Top Bottom