Check Boxes and Text Boxes

cherokee

lost and running
Local time
Tomorrow, 07:08
Joined
Jun 29, 2008
Messages
13
I have a table, called tblJobDetail, with the following fields:

jobid [primary key, and used to store job card number]
product, yes/no format
qty, number format

which I've created a sub-form from, where users can select a check box beside each product, and the quantity of each product is typed into the corresponding text box located to the right of the check mark.

My question is, can the text box be binded to the check mark, so that until the check mark is ticked, the box is greyed out and no quantity able to be entered?

I'm by no means new to access, but not a guru either, have just never had this 'challenge' before.

Hope someone can help?

;)
Chero
 
Hi,

Yes you can do something like the following:

Code:
If Me.Checkboxname = True Then
Me.Textboxname.Enabled = True
Else
Me.Textboxname.Enabled = False
End If
 
Ok, here's what I have:

Code:
Private Sub Ctl504Qty_BeforeUpdate(Cancel As Integer)
If Me.Ctl504Slider = True Then
Me.Ctl504Qty.Enabled = True
Else
Me.Ctl504Qty.Enabled = False
End If
End Sub

I still can't get the Qty box greyed out like I want? Being a complete newbie here, idiot proof instructions would be much appreciated ;)
 
The BeforeUpdating event of the textbox doesn't fire until data has been entered into the textbox, so you can't use it to set whether or not the textbox is enabled! This should do what you need:

Code:
Private Sub CheckBox_AfterUpdate()
 If Me.CheckBox = True Then
  TextBox.Enabled = True
 Else
 Me.TextBox = Null
   TextBox.Enabled = False
 End If
End Sub
Code:
Private Sub Form_Current()
 If Me.CheckBox = True Then
  TextBox.Enabled = True
 Else
   TextBox.Enabled = False
 End If

End Sub
 
Thanks Missinglinq

I pasted the code in that you provided, only the text box is now greyed out permanently, and checking the box on or off makes no difference - it just stays greyed out....

Apologies for the dumb post, but I really am only learning lol

Chero :)
 
Is the checkbox bound to a field in the underlying table/query?

I guess you need to copy and paste the actual code you have in your form.
 
I do this using the click event. it works
 
Thanks Missinglinq

I pasted the code in that you provided, only the text box is now greyed out permanently, and checking the box on or off makes no difference - it just stays greyed out....

Apologies for the dumb post, but I really am only learning lol

Chero :)
When you said you "pasted the code" that Linq provided, did you change the word TextBox to the actual name of your textbox?
 
When you said you "pasted the code" that Linq provided, did you change the word TextBox to the actual name of your textbox?

Yup...hehe...I should have known someone would ask that ;)

All sorted. This is how I did it:

1. I had a small routine to grey the boxes out by default on opening form:

Code:
Private Sub Form_Current()
Me.Ctl504Qty.Enabled = False
End Sub

I then added the OnClick Event to the check box:

Code:
Private Sub Ctl504Slider_Click()
If Me.Ctl504Slider = True Then
  Ctl504Qty.Enabled = True
 Else
 Me.Ctl504Qty = Null
   Ctl504Qty.Enabled = False
 End If
 End Sub

This may not be the best way to attack it, but as a first timer, I'm rather proud of myself :D

Thanks everyone for your help!
 
Sorry, but this makes no sense:
Code:
Private Sub Form_Current()
 Me.Ctl504Qty.Enabled = False
End Sub
Using this code, in the Form_Current event, means not only will the textbox be grayed out when the form opens, it will be grayed out every time your return to a record, even if the checkbox is checked and you have data in Ctl504Qty! The code in the Form_Current event needs to be just as it was given to you in my last post!

To gray it out when the form opens, place code in the Form_Load event.
 
Sorry, but this makes no sense:

Ok, point taken......as I've already said, I'm new to this, and may not have found the 'perfect' solution....so I'm glad you've responded. Now that I'm starting to get my head around this VBA stuff, will have another crack at it.
 
I'd be a bit wary about setting a checkbox to null. The only two valid values for a checkbox are 0 (false) and -1 (true) when you use the functionality in a form and the default value is 0. I know that Access will interpret any value that isn't -1 as false, but I think I'd rather use 0 than null for false.
 
To gray it out when the form opens, place code in the Form_Load event.
Done! Thanks again missinglinq for the tip.

The code in the Form_Current event needs to be just as it was given to you in my last post!

I did this:

Code:
Private Sub Form_Current()
If Me.Ctl504Slider = True Then
  Ctl504Qty.Enabled = True
 Else
    Ctl504Qty.Enabled = False
 End If
End Sub

Then I did this:

Code:
Private Sub Ctl504Slider_AfterUpdate()
If Me.Ctl504Slider = True Then
  Ctl504Qty.Enabled = True
 Else
    Ctl504Qty = Null
    Ctl504Qty.Enabled = False
 End If
 End Sub

As per your earlier post, and seems to have done the trick?
 
Last edited:

Users who are viewing this thread

Back
Top Bottom