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

Checkbox to disable textbox

Status
Not open for further replies.

rob9740

Technical User
Nov 21, 2001
30
IE
Hi all,
I was wondering could anybody help me out here. I've a checkbox that I want to use to disable two textboxes on a form, but only for the current record.
I can get the checkbox to disable the textboxes but it does so for all records on that form which I don't want. Also if I close and reopen the form the checkbox is still checked but the textboxes are re-enabled.
Has anybody any ideas or a different way to approach it I'd appreciate it.
Cheers,
Rob
 
You need to put some code in the On Current event for the Form and the On Change event for the checkbox.

The VBA code will look something like this:

If (Me![chkbox]) Then 'if chkbox is checked
Me![txtbox].Enabled = True
Else
Me![txtbox].Enabled = False
End If

hope this helps
wah
 
You need to use a combination of the Checkbox Click Event and the Form's On Current Event, along with Bookmarks.

Option Compare Database
Option Explicit
Dim lngRec As Long
Private Sub chk1_Click()
If chk1 = True Then
lngRec = Me.RecordsetClone.AbsolutePosition
txt1.Enabled = False
txt2.Enabled = False
Else
chk1 = False
txt1.Enabled = True
txt2.Enabled = True
lngRec = 0
End If
End Sub

Private Sub Form_Current()
Me.RecordsetClone.Bookmark = Me.Bookmark
If Me.RecordsetClone.AbsolutePosition = lngRec Then
chk1 = True
txt1.Enabled = False
txt2.Enabled = False
Else
chk1 = False
txt1.Enabled = True
txt2.Enabled = True
End If

End Sub


PaulF
 
Cheers Wah it works like a charm. I'd never thought about using the events for the form.
Cheers again,
Rob
 
Thanks aswell PaulF, looks a little complicated but I'll try it along with Wah's contribution. Is there much difference between the two in what they do???IS one method more\less error prone???
Rob
 
The difference is whether or not the CheckBox is Bound to a Field in the Recordset. If it is then just checking that value will do the trick. If it isn't then, you need to use the procedure I provided.

PaulF

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top