Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing the value of a control on a form

Status
Not open for further replies.

dfwelch

Programmer
Dec 5, 2003
51
US
Let's say I have a check box control named CheckBox1 on a form named Main and I want to check the value of that check box in an If .. Then statement in some VB code. Can someone write a sample If .. Then statement for me? I'm not sure exactly how to access the values of controls I put on a form in my VB code.

Is it just:
If Main.CheckBox1 Then
Code to be executed
End If
 
dfwelch
I'm not sure what you want to do with the value once you know it. I'm assuming that, depending on whether the check box is checked or not, something else will happen. Maybe this will give you a start.

Put code on the AfterUpdate event for your check box.
If Me.YourCheckBox = True then
Something
Else
Something different
End If

However, if you want something different, such as checking the value of the check box later on, we will need different code.

Tom

Hope that helps.

Tom


 
Yeah, my form will have a button on it to run some VB code, and I will want to check the values of several different controls on the form when I run the VB code. I do not need anything to happen immediately when I check the box.
 
dfwelch
If the first determination is the value of the check box, and then other determinations follow, wouldn't the same principle hold for the code behind your command button?

If Me.CheckBox = True Then
If Me.YourOtherControl = something
Do this
Else
Do Something different
End If

Since I don't know more about what you are trying to accomplish, I don't know what more to suggest.

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top