grey out 2 combo text boxes unless checkbox=True

G

Guest

Hi,
is it possible to grey out 2 combo text boxes to prevent data entry if a
checkbox is set to False? If checkbox is set to True, permit data entry.
Also, if the checkbox is changed from True to False while data is in the 2
combo boxes, I would like a MsgBox asking for confirmation from users to
delete this data.

Can I create a single On Click VBA script that does all of the above?

Thanks!
-Lynn
 
K

kingston via AccessMonster.com

Use the menu option Format->Conditional Formatting... and use an expression
like [CheckBox]=0 to change the background color of the two other controls.
Then use the form's OnCurrent event to check the value of the checkbox to
lock or unlock the controls (don't use enabled):

If Me.Checkbox = 0 Then
Me.Text1.Locked = -1
Me.Text2.Locked = -1
Else
Me.Text1.Locked = 0
Me.Text2.Locked = 0
End If

This is useful if you're using a continuous form where multiple records show
at the same time and you want the correct visual effect for all of them while
correctly determining whether data entry should be allowed.

Now, if data is changed, you'll want to use a procedure at the checkbox's
AfterUpdate event rather than the OnClick event:

Dim i as Integer
Dim strMsg as String

If Me.Checkbox = 0 Then
If IsNull(Me.Text1 & Me.Text2)=False Then
strMsg = "Delete existing data?"
i = MsgBox(strMsg, vbYesNo)
If i = 6 Then
'Delete data
Else
'Do nothing
End If
...

I've assumed the desired logic but you can easily change it to suit your
needs. Remember 0 is False, and -1 is True.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top