Microsoft Access would play

  toga 11:52 09 Oct 04

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 04

For i = 1 To 4

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

F.Visible = False

Next i

  toga 12:53 09 Oct 04

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 04

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 04

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.

Nintendo Switch (Nintendo NX) release date, price, specs and preview trailer: Switch price…

1995-2015: How technology has changed the world in 20 years

Best Photoshop video tutorials: 8 video tutorial websites for Photoshop

How to speed up a slow Mac: 19 great tips to make an iMac, MacBook or Mac mini run faster | Speed…