Solved

How to make a checkbox control with a Null value appear white instead of greyed out.

Posted on 2011-03-18
16
525 Views
Last Modified: 2013-11-28
Frm1 is based qry1. Qry1 is based on an outer join of tables tbl1 and tbl2 (the join is directed from tbl1 to tbl2). The controlsource of checkbox control chk1 on frm 1 is a boolean field of tbl2.

If there is no corresponding record in tbl2 for a given record in tbl1, then chk1 will appear greyed out (since it is Null). How can I make it appear white (False) when it has a Null valuel?
0
Comment
Question by:Milewskp
  • 6
  • 5
  • 3
  • +2
16 Comments
 
LVL 3

Expert Comment

by:DockieBoy
Comment Utility
Try using the Nz function,

Nz(MyControlSource,False)

Can you upload the db for a more specific answer :)
0
 
LVL 1

Author Comment

by:Milewskp
Comment Utility
Hi Dockie,
Good suggestion, but Nz would make it read only, and in my case I need read write.
0
 
LVL 3

Expert Comment

by:DockieBoy
Comment Utility
Hmm, my bad, I thought it was read only from the sounds of the query your form is based on, I don't use a lot of bound forms, but I'll have a quick play :)
0
 
LVL 3

Expert Comment

by:DockieBoy
Comment Utility
Sorry, I have just re read your post and I just want to be sure.  You have a Left Outer Join and the check box is included in the results but is null because there is no record that maches the Join critera.

Not sure how you would be able to make changes to the value of this check box anyway?

Can you please provide an example :)
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
I have a solution for you. This solution requires you to add a dummy field to one the tables. If you are okay with that, please let me know to discuss it.

Mike
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
If the answer is yes, then add chkDummy to  tbl1 with Yes/No setting. Now, on your form, binde your checkbox (chkbox1) to this field not the one from tble2.

Also, on your form add chkbox2 to be binded to yes/no from table2. Make chkbox2 invisible.

In the Current event of the form, have:

If chkbox2 = true then
   chkbox2 = true
Else
   chkbox2 =False
End If

Mike
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 500 total points
Comment Utility
Word of caution...

In the existing grayed out check box version, please test VarType of the check box when it is grayed out. In the Current even of form prior to applying my solution have:

MsgBox VarType(Me!chk1)

It may produce 9 when it is grayed out. Object VarType is 9. If it is 9, then the code should change to:


If VarType(chk1)=9 then
   chkbox2 =False
elseif chk1= True then
   chkbox2 =True
Else
   chkbox2 =False
End If

Use this version regardless. My last post needed some correction any way.

Mike

If chk1 = true then
   chkbox2 = true
Else
   chkbox2 =False
End If



0
 
LVL 57

Expert Comment

by:Jim Dettman (Microsoft MVP/ EE MVE)
Comment Utility

 Nice to see you around Mike :)

JimD.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 44

Expert Comment

by:GRayL
Comment Utility
Ditto :)
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
Thanks guys. I am here to learn some more from both of you.

Mike
0
 
LVL 1

Author Comment

by:Milewskp
Comment Utility
Hi Mike,
Interesting idea. Thanks.  It got me thinking.

In my case the relationship between table1 and table2 is one-many, so changing the value of chkdummy in Table2 would affect multiple records on the form.
But, addingf the extra field to Table1 may be unneessary. What if chk1 is a calculated control:
= Nz([Chk2], False)

with OnClick event:
[chk2] = Nz([chk2], True)


- Your thoughts?
0
 
LVL 1

Accepted Solution

by:
Milewskp earned 0 total points
Comment Utility
Hi all,
I've this and it seems to work (chk1 is greyed out when Null; chk2 is always white and checked or unchecked but always white):

chk1.Visible = False
chk2.Visible = True
chk2.Controlsource =Nz([Chk1],False)

Private Sub chk2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
      Me.chk1 = Not Nz(Me.chk2, False)
End sub
0
 
LVL 1

Author Comment

by:Milewskp
Comment Utility
Thanks for your help folks, I'll go with my solution and give the assist to Mike.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
Milewskp<

My appology for not responding earlier.

If you have a solution that you like that is fantastic. FYI, adding chkDummy and data in it is of no conseqyence (this is why it ia called dummy). The reason we wanted to have it so that the the visible check box is bound to something (this is essential if you are showing multible records in detail section).

This dummy checkbox, nonetheless, displays the accurate data from theother table. Also, just in case, you wanted to upload a sample datbase, I will be glad to work with you on it.

Regards,

Mike
0
 
LVL 1

Author Comment

by:Milewskp
Comment Utility
Hi Mike,
I'm satisifed that this question is closed, but if you'd like to discuss further, post away.

Thanks again.
0
 
LVL 1

Author Closing Comment

by:Milewskp
Comment Utility
.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now