How to make checkboxes checked by default in MS Access 97

  • Thread starter Thread starter kushalbalgobin
  • Start date Start date
K

kushalbalgobin

Hi i have several checkboxes on my MS Access 97 forms in order to
monitor if an item is required. By Default all items should be checked
(required) and later if some of them are not required then i can
uncheck them.Could someone help me please how to make checkboxes
checked by default in MS Access 97 (in the table for preference).
 
In the table design, change the DefaultValue property to True

for records that are already created, you can use an UPDATE query to set
them all to TRUE

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
I tried that setting the default value to true in the table and even on
the form still they remain unchecked
 
in that case, try changing the DefaultValue property for each control on
forms that you have already created...

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
my table is still empty and i have about 30 items to check, is there
another way to make the checkbox checked by coding for example
 
Hi Prav,

with all due respect, it is quicker to (1) go to design view of the
table, (2) manually enter DefaultValue--> True (type first one, copy, go
to next Yes/No field, paste in DefaultValue property, etc) ... than it
is to write a program to do it (but I did it for you anyway ;) ...
making certain assumptions )

Because I did not specify fieldnames in the program, it loops through
ALL Yes/No fields... if this is not what you want, you will have to
manually change them after the routine runs)

modify the parameters sent to setYnDefaultValue in RunsetYnDefaultValue
for your values (first tablename in quotes and the what you want to set
DefaultValues to, true or false)

Make sure you have a reference to a Microsoft DAO Library
from the menu in a module window --> Tools, References...
(check Microsoft DAO 3.6 Object Library or something similar)

Then, compile the db*

After everything compiles okay, then create a new general module



put this code in a general module

'~~~~~~~~~~~~~~~~
Sub RunsetYnDefaultValue()
setYnDefaultValue "YourTablename", True
End Sub

'~~~~~~~~~~~~~~~~
Sub setYnDefaultValue( _
pTablename As String, _
pBoo As Boolean)

'written by Crystal
'strive4peace2006 at yahoo dot co,
'8-16-06

'NEEDS REFERENCE TO
'Microsoft DAO Library

On Error GoTo Proc_Err

Dim db As DAO.Database, tdf As DAO.TableDef
Dim fld As DAO.Field, i As Integer

Set db = CurrentDb
Set tdf = db.TableDefs(pTablename)

i = 0

With tdf
For Each fld In tdf.Fields
If fld.Type = dbBoolean Then
fld.DefaultValue = pBoo
i = i + 1
End If
Next fld
End With

db.TableDefs.Refresh

MsgBox "Done setting " & i _
& " Yes/No fields in " _
& pTablename _
& " to DefaultValue = " & pBoo, , "Done"

Proc_Exit:
On Error Resume Next
Set fld = Nothing
Set tdf = Nothing
Set db = Nothing
Exit Sub

Proc_Err:
MsgBox Err.Description, , "ERROR " & Err.Number & " setYnDefaultValue"
'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume
Resume Proc_Exit

End Sub


'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a module window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)
'~~~~~~~~~~~~

then, after you paste in this code, compile your database again...

when everything is okay, click your mouse in RunsetYnDefaultValue and
press F5 to Run!

Voila! Check the specified table and all DefaultValue properties of
YesNo fields should be whatever you specified (True in the example).

'~~~~~~~~~~~~~~~~~~`

One thing I want to mention ... use of Yes/No fields -- especially that
many ... implies that your data structures perhaps have opportunities
for improvement...


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
strive4peace2006 at yahoo.com
*
 
Thank you strive4peace. It works
However i'm trying to put a checkbox condition on my form
(form_current) but nothing is happening. Here is my code

If Me.chkLand_Required Then
Call Land
Else
cmbLand_Who.Enabled = False
txtLand_AgDate.Enabled = False
txtLand_AtDate.Enabled = False
txtLand_ComDate.Enabled = False

If the chkLand is checked then call Land.
if not then disable textboxes.
 
you're welcome

can you please post the complete code behind your form

for instance, where is the resot of the code for the procedure you
pasted. Also, where is the code for "Land" since you are calling it?

you cannot disble any control that has the focus --- you should set the
focus to something else before you disable controls


ie:
me.controlname.SetFocus
me.someOther_controlname.Enabled = False


did you compile the code:

'~~~~~~~~~ Compile ~~~~~~~~~

Whenever you change code or references, your should always compile
before executing.

from the menu in a module window: Debug, Compile

fix any errors on the yellow highlighted lines

keep compiling until nothing happens (this is good!)


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
If Me.chkLand_Required Then
Call Land '( sub to display flags for Land according to the dates)
Else
cmbLand_Who.Enabled = False 'person to contact
txtLand_AgDate.Enabled = False ' agreed date
txtLand_AtDate.Enabled = False 'anticipated date
txtLand_ComDate.Enabled = False 'completed data
End If
 
*where is the code for "Land" since you are calling it?*


Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
glad you got it :) happy to help

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

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

Back
Top