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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check Box Control Setting Text Box 1

Status
Not open for further replies.
Mar 9, 2007
48
US
I'm curious to know why this isn't working and I'm sure the answer is quite simple but for whatever reason I cannot sort it out.

Private Sub Adnma_Click()

Dim Ctl As Control

For Each Ctl In Me.Controls

If Ctl.ControlType = acCheckBox Then

If Ctl.Value = True Then

Me![RcrdCmp] = "Y"

Else

Me![RcrdCmp] = ""

End If

End If

Next

End Sub

If I comment out the Else and Me![RcrdCmp] then the RcrdCmp field will set to "Y", however, when I leave the else statement nothing works. What am I missing?
 
I guess you wanted something like this:
Code:
Private Sub Adnma_Click()
    Dim Ctl As Control
    Me![RcrdCmp] = ""
    For Each Ctl In Me.Controls
        If Ctl.ControlType = acCheckBox Then
            If Ctl.Value = True Then
                Me![RcrdCmp] = "Y"
                Exit For
            End If
        End If
    Next
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
How are ya New Postmizenerman . . .

According to your post origination [blue]Me![RcrdCmp][/blue] will be set [blue]according to the last checkbox checked[/blue]. I doubt this is what you want.

[blue]PHV[/blue] has posted a modification of your code that will set [blue][RcrdCmp][/blue] according to the 1st checkbox found that is checked. If you wanted to know if any of the checkboxes were set to true ... this will do it. However, we don't know if this is what you want either!

[blue]Your Thoughts? . . .[/blue]

See Ya! . . . . . .

Be sure to see faq219-2884 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Duane and TheAceman1, my apologies for not posting what I was trying to accomplish but TheAceman1 is correct, setting the RcrdCmp field according to the last checkbox checked was not want I wanted. I wanted to check if any of the checkboxes were checked. PHV, thanks for showing me the error of my ways!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top