MS Access Hiding Text Boxes Based On User Selection VBA

I received an email from a guy to the effect of wanting to
hide some textboxes based on a value entered into a single

In my answer, I came up with a way to do this, and
decided to share it with you…

This example will show you how to hide
the textboxes on your form based on the user’s selection.

This helps limit the user’s focus to just the fields necessary
for input.

Tweak the code around, and fit it into your situation.

(You can get the database below)

[sourcecode language=”vb”]

‘ERIK LOEBL(713)409-7041

Option Compare Database

Private Sub btnHide_Click()
Dim strHide As String

Select Case Me.cboHide
Case 1
strHide = "2,3,4,5,6,7,8,9,10"
Case 2
strHide = "3,4,5,6,7,8,9,10"
Case 3
strHide = "4,5,6,7,8,9,10"
Case 4
strHide = "5,6,7,8,9,10"
Case 5
strHide = "6,7,8,9,10"
Case 6
strHide = "7,8,9,10"
Case 7
strHide = "8,9,10"
Case 8
strHide = "9,10"
Case 9
strHide = "10"
End Select

hide (strHide)

End Sub

Sub hide(these)
Dim varThese As Variant
Dim intCount As Integer
Dim strControlName As String

varThese = Split(these, ",")

For intCount = 0 To UBound(varThese)
If Len(varThese(intCount)) = 1 Then
strControlName = "txt0" & varThese(intCount)
strControlName = "txt" & varThese(intCount)
End If
Forms("frmMain").Controls(strControlName).Visible = False

End Sub

Private Sub btnShow_Click()
Dim intCount As Integer

For intCount = 0 To Me.Controls.Count – 1
If Me.Controls(intCount).Visible = False Then
Me.Controls(intCount).Visible = True
End If

End Sub


Click here for the file:

Offsite Related Information:

“Go Fund Me” Page

($5 suggested amount)

(…10% of your gift amount will go to charity)

Free! Subscribe To Our YouTube Channel!

Free MS Access VBA Programming Course

Facebooktwitterredditpinterestlinkedinmailby feather
Tags: , , , , , , , , ,