Microsoft Access would play

  toga 11:52 09 Oct 2004

Hello, I am trying to learn about using visual basic for accrss. I have created a form with 2 lables and 2 text boxes on it (the names given to the lables and text boxes is 1, 2, 3 and 4). On the click of a button I wanted to set their properties ".Visible" to false.

This works fine if I used a seperate line of VB as below, where the box [ ] would contain the corresponding number e.g. [1] or [2] etc.:

Forms![EmployeesLogin]![1].Visible = False

However, I then tried to use a "For Loop" to loop through and set the properties to false, without success e.g.

Dim F As String
Dim i As Integer
For i = 1 To 4
F = "Forms![EmployeesLogin]!["
F = F & i & "].Visible = False"
MsgBox F

The code places the correct corresponding number in the [ ] but doesn't execute. Any ideas please?

Many thanks

  VoG II 11:58 09 Oct 2004

For i = 1 To 4

F = "Forms![EmployeesLogin]![" F = F & i & "]"

F.Visible = False

Next i

  toga 12:53 09 Oct 2004

Hello VoG

I tried the above but got a message saying "Invalid Qualifyer" for F.Visible = False

I don't understand how it works with single lines of code but dosen't with the for loop.


  VoG II 13:08 09 Oct 2004

I'm not familiar with Access but I use VBA in Excel.

I think that for this to work you will need to Dim F as a Form

Dim F As Form

Then you may need to use something like

Set F = "Forms![EmployeesLogin]![" F = F & i & "]"

F.Visible = False

The reason that nothing was happening with your original code is that you were just building up a text string with .Visible = False tagged onto the end. To get the code to work, you need to build-up the name of the form and set it as a form then set its Visible Property to False.

click here may help you.

  AccessMoron 18:07 12 Oct 2004

The following code should turn off, and then on all text box's and lables on the form

'Used to turn it on and off
Dim blnStatus As Boolean

Private Sub Command0_Click()

Dim obj As Object

For Each obj In Me.Form

'Find out what control we are looking at

Select Case obj.ControlType

Case acCommandButton

Case acTextBox

obj.Visible = blnStatus

Case acLabel

obj.Visible = blnStatus

End Select


blnStatus = Not blnStatus

End Sub

This thread is now locked and can not be replied to.

Elsewhere on IDG sites

HTC U12 Plus review: Hands-on

Frida Kahlo's life, art and legacy explored in Google's new giant online collection and app

Best Android emulators for Mac

Comment importer des contacts d’un iPhone à un autre iPhone ?