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

Can VB Code be used to UnCheck...a Checkbox that set to True by a user 2

Status
Not open for further replies.

testkitt2

Technical User
Apr 28, 2004
193
US
hello Tipsters

I have a main form that has a subform...in that subform there is a checkbox whereby the user will click and turn the checkbox to yes or true.. this subform is attached to a report that will only print those items that has a checkbox ..checked off. I want to have the checkbox unchecked after the report is printed. thus resetting the subform for the next set of instructions. If you manually uncheck the box...thats fine. but some users forget to uncheck the box even after printing the report.

the main form is called: "unit"
the subform is called: "SubParts"
the checkbox (on the subform) is called: "Print Order"

what I'm trying to do is either create a command button that will uncheck all records that have a checkbox equal to true or when the user prints his report that is based on the checkbox being true that the checkbox becomes false.

Is this possible

Thank you
JZ



Testkitt2
 
Private Sub Form_Load()
Me!SubParts.Form!PrintOrder = False
End Sub
 
Thanks Zion7
copied and pasted code in several places..one at a time...
did not rec and error but it did not uncheck the box.

SubParts is the name of the sub form inside of my mainform.

mainform name is called: BackLogAdmin
subform name is called: SubParts
(Subparts derived from a small form called: Req_Details).
I used the following...
Code:
Me!Req_Details.Form!Check16 = False
Me.Req_Details.Form!Check16 = False
Me!SubParts.Form!PrintOrder = False
Me.Req_Details.Form![Print Order] = False
Me.SubParts.Form![Print Order] = False
I tried all of the above one at a time...but none of them worked.
I hope you can lend a hand...if possible..
I could always manually uncheck the checkbox...but then I would have to jump from record to record to see if someone else left the checkbox in that record checked off.

Thank you
JZ

Testkitt2
 
quick note:
The first post had incorrect form names..the last post dtd 9-18-05 has the correct form and subform names
thk
JZ

Testkitt2
 
I don't know JZ, looks fine from here, syntax wise?

Is the code conflicting with other code, elsewhere?

Try to just turn it on & off Programmatically, with a cmdButton, to see if the references are correct. Or use a msgBox to check the value(checking the reference )

???
 
hey thanks Zion7,
The reason for all the different lines of code...is that when in design mode the last subform that is on top of the other subform was the form i was looking at...not realizing the subform i needed to look at was about the 3rd one down.

anyway i tried the command button as you suggested and it works... but check this out.
the subform presents itself in data mode thus showing a bunch of records at once. if i click or select one of the records in the datasheet and its checkbox is set to true the command button will uncheck the box..great..now how do I add something that selects all the records in the datasheet to have the command button uncheck everything.

my current code behind the command button is
Code:
Private Sub CmdBox_Click()
Me.Req_Details.Form!Check16 = False
End Sub
thanks again..any suggs are appreciated.
JZ

Testkitt2
 
What is the underlaying SQL code of Req_Details's RecordSource ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
You could use the Controls collection, or a rercordset.

Did you say that the subform is 3 layers down?

Me.req_Details.Form.sfrmNext.Form!chk456 ???

If so
Dim rec As DAO.Recordset

SEt rec = Me.req_Details.Form.sfrmNext.Form.Recordset
Do until rec.EOF
rec.edit
rec!chk456 = False
rec.Update
rec.movenext
loop

Or Contriols

Dim ctl as control

For each ctl in Me.req_Details.Form.sfrmNext.Form(controls)

If ctl.ControlType = acCheckBox Then...
 
Thanks to all who responded

The SQL for Req_Details is as follows:

Code:
SELECT Unit.Truck, Unit.[Vin #], Unit.Year, Unit.Make, Unit.Model, PartsDescription.DateLock, PartsDescription.Qty, PartsDescription.[Part No], PartsDescription.[Print Order], PartsDescription.Description, PartsDescription.Technician, PartsDescription.[Truck Status], PartsDescription.Comments, PartsDescription.Quotes, [Qty]*[Quotes] AS TPrice, tbVendor.[tbVendor Name], tbVendor.Address, tbVendor.Tel, tbVendor.Account
FROM tbVendor, Unit INNER JOIN PartsDescription ON Unit.Truck = PartsDescription.Truck
WHERE (((Unit.Truck)=[Enter Equipment or Stock]) AND ((PartsDescription.[Print Order])=Yes) AND ((PartsDescription.Technician)=[' Enter your first initial and last name to print requisition ']) AND ((tbVendor.[tbVendor Name]) Like [Enter The First Few Characters of the Vendor: ] & "*"));

JZ


Testkitt2
 
Quick note:
The above query... will print out a requisition form (via report) once the questions are satisfied. and one of them is that the checkbox is checked off.. but after printing set request..the user does not uncheck the box..leaving a messing trail of records with the checkbox checked off.
JZ

Testkitt2
 
CurrentProject.Execute "UPDATE tblVendor SET chk456 = Null
 
Private Sub CmdBox_Click()
Dim rs As DAO.RecordSet
Set rs = Me!Req_Details.Form.Recordset
With rs
.MoveFirst
While Not .EOF
.Edit
![Print Order] = False
.Update
.MoveNext
WEnd
End With
Set rs = Nothing
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Zion7
do I have to replace any part of this code with...like other names....
CurrentProject.Execute "UPDATE tblVendor SET chk456 = Null"
and where to I apply this piece?

Hello PHV
I will try your suggs as well.
Thanks to all
JZ

Testkitt2
 
Hey as I await an answer from Zion7
I want to post what I have...
PHV...your code works...the only thing is this...its
grabbing all the checkboxes for the current record thats in view...and when i click on the command button...(really I want the boxes uncheck differently.) but anyway..it unchecks all the checkboxes currently checked off for that record..can the command button code be altered to select all records in req_details...like a clean up sort of command...cause all records who have a check mark will print on the requisition..
Thanks
JZ

Testkitt2
 
A global clean-up ?
Private Sub CmdBox_Click()
CurrentDB.Execute "UPDATE PartsDescription SET [Print Order] = False"
Me!Req_Details.Form.Refresh
End Sub

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Thanks to all who help with this thread..Zion7,,,PHV


The code below..suggested by PHV is what I ended up with.
It works great...it cleans it all up. Now when a user goes to add a purchase order and clicks new order all the previous check boxes left check-off by other users will be erased, and the curent user will have to check off the lines he wishes to print on the order.


Code:
Private Sub CmdBox_Click()
Dim rs As DAO.Recordset
Set rs = Me!Req_Details.Form.Recordset
CurrentDb.Execute "UPDATE PartsDescription SET [Print Order] = False"
Me!Req_Details.Form.Refresh
Set rs = Nothing
End Sub

Thanks again....for completing this thread...
JZ

Testkitt2
 
TestKitt, good to hear it'sorking but, only these 2 lines are necessary...

CurrentDb.Execute "UPDATE PartsDescription SET [Print Order] = False"
Me!Req_Details.Form.Refresh

as you can see, your recordset has no purpose, it's neither reading or writing....just for the record.
 
Hello to all
Zion7 I like to re open this thread... the last code posted on sep 20 was fine ..the only thing is that I now had another subform (view as a datasheet) that has a check box on the main form and when I copied and paste the code ..changing the names to match I received this error..

Code:
Too Few Parameters. Expected 3

Can you help..
Thanks
JZ

Testkitt2
 
hello to all
if someone else has a little time...pls read the error
msg and advise accordingly.

Thank you'
JZ

Testkitt2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top