Results 1 to 3 of 3

Thread: Ahh crud, another problem

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Angry Ahh crud, another problem

    Ok, this time I need to save the state of all controls on a form, such as which option buttons in an array are selected, the text inside a combo box, whether or not certain checkboxes are checked or not, etc.

    I keep finding stuff for this, but I never can remember where, and my dumbheaded self keeps forgetting to bookmark the pages I find this stuff at.

  2. #2

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Something like this, perhaps:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type AllControls
    4.     ctlName As String
    5.     ctlValue As Variant
    6. End Type
    7. Dim ControlState(255) As AllControls 'max number of controls allowed on a single form
    8.  
    9. Private Sub Form_Load()
    10. Dim i%, ctl As Control
    11.  
    12.     For Each ctl In Controls
    13.         ControlState(i).ctlName = ctl.Name
    14.         If TypeOf ctl Is OptionButton Then
    15.             ControlState(i).ctlValue = ctl.Value
    16.         ElseIf TypeOf ctl Is TextBox Then
    17.             ControlState(i).ctlValue = ctl.Text
    18.         If TypeOf ctl Is CommandButton Then
    19.             ControlState(i).ctlValue = ctl.Caption
    20.         End If
    21.         i = i + 1
    22.     Next ctl
    23.  
    24. End Sub
    Roy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width