Check Box Problem

G Marshall

Board Regular
Joined
Dec 31, 2002
Messages
134
Hello

I have an Access Database with an Orders / Invoice form. This form has six fields for data input and one check box. The check box should only be checked by the user when the other six fields contain data.
How can I prevent the user checking the check box when one or more of the other six fields have no data.

Appreciate any help


Gerald Marshall
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
probably the simplest way is to check if the other fields are completed when the checkbox is used and if not send the users back to the other fields. Yell if you need help with the code for this.
 
Upvote 0
Thanks for that

That is exactly what I would require, and I would appreciate help with the code. :oops:

Thanks


Gerald
 
Upvote 0
Code:
Private Sub Check0_Click()

if isnull("txt1") then
    msgbox("Please complete text1.")
    txt1.setfocus
    exit sub
end if

if isnull("txt2") then
    msgbox("Please complete text2.")
    txt2.setfocus
    exit sub
end if

end sub

and on and on through all yur textboxes...

Replace my textbox names (txt1, txt2) and checkbox name (chk0) with your's.

edit:

Just thinking, if you want to be clever(lazy), you can name your textboxes something like 'text1", "text2", "text3" etc, just anything with a sequential number at the end, and then use code like this:
(use the number of textboxes for your value of i, in this case, 5 textboxes would mean we need to use 5 for i)
execute on the check click event as before
Code:
for i = 1 to 5
    if isnull(me.controls("text" & i)) then
        msgbox("Please complete field " & i)
        me.controls("text" & i).setfocus
        exit sub
    end if
next i

That should save some time coding, plus make your form more reusable.
 
Upvote 0
one refinement to add would be to use the Before Update event so that you can cancel their use of the check box.
Code:
for i = 1 to 5 
    if isnull(me.controls("text" & i)) then 
        msgbox("Please complete field " & i) 
        me.controls("text" & i).setfocus 
         cancel = true
        exit sub 
    end if 
next i 

HTH

Peter
 
Upvote 0
Hi
Thanks to both the previous contributors. I have used the code supplied and its works perfectly.

Much appreciated!

Gerald Marshall
 
Upvote 0

Forum statistics

Threads
1,221,618
Messages
6,160,873
Members
451,674
Latest member
TJPsmt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top