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

Loop through controls on continuous form 1

Status
Not open for further replies.

aw23

Programmer
Nov 26, 2003
544
IL
I have a continuous form with checkboxes. I need to loop through all the checkboxes on the form. Is this possible?
How?
Thanks
 
explicitly where they are just checkboxes you'll need something that identifies them, or you'll have to loop through all the controls and check to see if it's a check box.

You can do the following:

Name each of your checkboxes something like; chkbox1, chkbox2...

then

for i = 1 to n 'where n is the last checkbox
me.controls("chkbox" & i).value = true 'or whatever you want to do
next i

Additionally you can loop through all the controls on the form, but that would take longer, but - it would not need updated if you ever added more check boxes. You can find sample code of looping through controls by clicking on search and typing "Looking through controls"



Randall Vollen
National City Bank Corp.
 
Sprry, let me explain the problem. I have 2 columns of chckboxes on a continuous form. (So really I only have two is design view)
Check1, check2
I want that whenever check1 is checked, check2 should also be checked.

Private Sub Check1_Click()

If Me.Check1 = True Then Me.Check2 = True
If Me.Check1 = False Then Me.Check2 = False
end sub

However this code only works when the first checkbox in the column is checked and not for all the continuous boxes. I thought maybe if I'd loop through all of them and check which are checked and then check off the corresponding box. I don't know...
 
You'll probably have to loop through all the records of your selection.

Open a recordset and check the data, then change your data based upon your requirements.

use ADO or DAO. I recommend ADO, but if you're not running MS2k or higher you'll be forced to use DAO.



Randall Vollen
National City Bank Corp.
 
That's what I figured I'd have to do. Thanks
 
But how do I know which record they are up to? I am really confused with these continuous forms. When they check the first checkbox I want to check off the corresponding one but how do I know which checkbox they marked off? How do I know if it is the first, second or twenty-third? How do I refer to a specific row in a continuous form?
This is actually the first time I am dealing with a continuous form.
 
Are Check1 and Check2 bound ?
If yes you can try this:
[tt]Me.Check2 = Me.Check1[/tt]
in the Check1_AfterUpdate event procedure and perhaps in the form's Current event procedure too.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
That worked, thanks so much. But I still have one problem with it.
My subform has several columns. The first is a checkbox the second is a client the third is a contact and the fourth is a checkbox. The first checkbox corresponds to the client and the second to the contact. There can be several contacts within one client so I can have one client listed several times, one for each contact.

Now, when the user checks off a client, I want all the checkboxes for that same client checked off. This is no problem because it is bound so I simply requery. Now, when user checks off a client I want all the contacts within that client marked off. I thought it would be simple beacause since all the checkboxes for the client are marked off I thought I could just see what's checked and mark off all the corresponding ones. But that doesn't seem to work. Your code works only for the client that was checked. If there are more contacts for that client it will not be checked.
 
Can you please post the SQL code of the RecordSource of the subform ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
SELECT company.Com_Name,company.noemail, customers.NoEmail,customers.C_FName, customers.C_LName, customers.C_Email
FROM customers LEFT JOIN company ON customers.Company_ID = company.Company_ID WHERE (instr(c_email," & "'@'" & ")>0) AND (company.Company_ID IN (" & srch & "))"
order by company.com_name


-search is a list of id's
 
I'm astonished this recordset is updatable ...
Anyway, in the AfterUpdate event procedure of the subform you may add code like this:
DoCmd.RunSQL "UPDATE customers SET NoEmail=" & Check1 & " WHERE Company_ID=" & [name of company_ID control]
DoEvents
Me.Refresh
Another way is to play with the Me.RecordsetClone object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Here is a simple routine I use occationally when I want to update records (on screen without getting the recordset again) using a bound continuous form.

Sub UpdateFormRecords()
Dim Cnt

Cnt = 0
DoCmd.GoToControl "SampleText"

DoCmd.GoToRecord , , acFirst
Do
'Do something (like Me.FirstName="Brad")

Cnt = Cnt + 1
MsgBox "Updated Record # " & Cnt

On Error GoTo NoMoreRecords
DoCmd.GoToRecord , , acNext
Loop
Exit Sub
NoMoreRecords:
DoCmd.GoToRecord , , acFirst
MsgBox "Update complete."
End Sub
 
Thanks PHV, it didn't work. Still did not update the corresponding row.
 
bradmaunsell,
Can you please put in some comments and explain your code? I'd like to try it. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top