Can WITH statements be nested?
example
dim rst as Recordset
dim btn as CommandButton
dim i as integer
With rst
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
for i = 1 to 4
With btn
.Name = "Button" & i
.Visible = true
End With
next
.MoveNext
Loop
End If
End With
I have a form with a Tabstrip object, an unbound subform object and a series of buttons. Based on the TAB selected in the tabstrip, a particular set of data is displayed in the subform area and the buttons take on certain values and attributes. It's all working great when I code it directly, but I am trying to clean up the code and streamline the process. I have placed all the button data into a table which I filter down to get the necessary records. I then want to loop through all the records (hence the first WITH and DO-LOOP) and then loop through all the buttons, setting the various attributes and values (hence the need for the 2nd WITH and the FOR-NEXT loop), but I am not sure if the WITH can be nested like this. How will ACCESS know which WITH it is working with (trying saying that 10 times real fast!)
I haven't actually tried it yet. The specific code is more complicated than what is shown and I didn't want to get into it unless it has a chance of working.
Thanks for the help!
example
dim rst as Recordset
dim btn as CommandButton
dim i as integer
With rst
If .RecordCount > 0 Then
.MoveFirst
Do Until .EOF
for i = 1 to 4
With btn
.Name = "Button" & i
.Visible = true
End With
next
.MoveNext
Loop
End If
End With
I have a form with a Tabstrip object, an unbound subform object and a series of buttons. Based on the TAB selected in the tabstrip, a particular set of data is displayed in the subform area and the buttons take on certain values and attributes. It's all working great when I code it directly, but I am trying to clean up the code and streamline the process. I have placed all the button data into a table which I filter down to get the necessary records. I then want to loop through all the records (hence the first WITH and DO-LOOP) and then loop through all the buttons, setting the various attributes and values (hence the need for the 2nd WITH and the FOR-NEXT loop), but I am not sure if the WITH can be nested like this. How will ACCESS know which WITH it is working with (trying saying that 10 times real fast!)
I haven't actually tried it yet. The specific code is more complicated than what is shown and I didn't want to get into it unless it has a chance of working.
Thanks for the help!
Last edited: