VB 6 and checkboxes

From a Beginner.
I have a program I am writing and using alot of checkboxes
on forms. My problem is when I close the form to move to
the next form the checkboxes clear. I do not want that
I would like them to stay check so when I go through
all the forms and are ready to print it will print the
ones I have checked. Any help..
Thanks
John

Comments

  • [b][red]This message was edited by infidel at 2002-12-26 8:15:54[/red][/b][hr]
    : From a Beginner.
    : I have a program I am writing and using alot of checkboxes
    : on forms. My problem is when I close the form to move to
    : the next form the checkboxes clear. I do not want that
    : I would like them to stay check so when I go through
    : all the forms and are ready to print it will print the
    : ones I have checked. Any help..

    Yours is a problem of "scope". When you destroy a form object, all variables within it go out of scope and are unavailable to you. The simple solution is to put variables in a place that does not go out of scope between form incarnations. Add to your project a code module and fill it with variables declared "As CheckBoxConstants". Then when you unload a form, you can store the state of your checkboxes in these variables.

    CheckBoxValues.bas
    [code]
    Option Explicit

    Dim Form1_CheckBox1 As CheckBoxConstants
    Dim Form1_CheckBox2 As CheckBoxConstants
    Dim Form1_CheckBox2 As CheckBoxConstants
    [/code]

    Form1.frm
    [code]
    Private Sub Form_Unload(Cancel As Integer)

    Form1_CheckBox1 = Me.CheckBox1.Value
    Form1_CheckBox2 = Me.CheckBox2.Value
    Form1_CheckBox3 = Me.CheckBox3.Value

    End Sub
    [/code]

    Then when you are finished, you will have the state of all your checkboxes available to you because the closing of forms will never cause these variables to go out of scope.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion