Accessing Groupboxes

blumonde

Well-known member
Joined
Jul 26, 2005
Messages
68
Programming Experience
Beginner
Hiya Gentlemen,

I have a long windows form. It has 100 text fields on it. I name them field#1 to field#100. The form size is set to display from field#1 up to field#50 only. The form has a verticle scrollbar so that users can access fields that are below field#50.

I have thought of a better way to do this. Instead of using the scrollbar to access fields 51 to 100 during data entry, I created two groupboxes. Groupbox1 contains field#1 to field#50. Groupbox2 contains field#51 to field#100. These two groupboxes are overlaying each other on the same page. No more scrolling up and down. I created a left and a right arrow buttons so that users can switch from groupbox1 to groupbox2 and vice versa. When groupbox1 is visible, groupbox2 is invisible and vice versa.

The problem I have is that when I click the update button, it seems that my code will only recognize the values on groupbox1 but not groupbox2. I did enter values to fields on both groupboxes for testing.

Here is how I access the values of the fields on both groupboxes:
Note: I set the tab index order of these fields from 1 to 100.

'****************
Dim currentControl As Control
Dim sUpdateme as string
currentControl = Me.field1

while not true
If currentControl.Text <> "" Then' Check if the current text field is empty or not

sUpdateme = currentControl.Text.Trim ' Apply the value from the screen
end if

currentControl = Me.GetNextControl(currentControl, True) ' Increment to the next field

if currentcontrol.tabindex = 100 then exit while

end while
'*****************

My code above works fine when I didn't use the groupboxes at first.

I don't know what I did wrong in a case like this. Could someone please shed a light on me. Thanks.

Please help.

blumonde
 
Last edited:
If a GroupBox is not visible then you cannot focus a control it contains. You may want to leave both GroupBoxes visible and just adjust the z-order by calling BringToFront whenever a control on that GroupBox raises an Enter event.
 
jmcilhinney said:
If a GroupBox is not visible then you cannot focus a control it contains. You may want to leave both GroupBoxes visible and just adjust the z-order by calling BringToFront whenever a control on that GroupBox raises an Enter event.

Thank you, jmcilhinney :)

It works.

Cheers,

blumonde
 
Back
Top