TableDef question

R

Robert Nusz @ DPS

in using the following sample code, how do I define a field in a table for
the Yes/No switch, and set its value to a default value of yes.

Dim fld1 as Field
Dim fld2 as Field
Dim fld3 as Field
Dim fld4 as Field
Set fld1 = NewTbl.CreateField("CaseNo", dbInteger)
Set fld2 = NewTbl.CreateField("MyName", dbText, 50)
Set fld3 = NewTbl.CreateField("DatePaid", dbDate)
Set fld4 = NewTbl.CreateField("IsPaid", dbYesNo)
NewTbl.Fields.Append fld1
NewTbl.Fields.Append fld2
NewTbl.Fields.Append fld3
NewTbl.Fields.Append fld4
CurrentDb.TableDefs.Append NewTbl

where field 1 is named CaseNo and has an integer value default
field 2 is named MyName and has text value, length of 50 characters,
field 3 is named DatePaid and has date value (dbDate) with short date format,
and field 4
is named IsPaid, and is a switch field either yes or no value (checkmarked)
and defaults to No.

what dbxxxxx value do I use to define a yes/no field via code and how do I
set its default value to no.

Thanks in advance,

Robert
 
A

Allen Browne

The answer to your question is:
fld4.DefaultValue = "Yes"

However, the code is not showing a CreateTableDef() to assign the NewTbl
before you CreateField() on it.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

message
news:D[email protected]...
 
R

Robert Nusz @ DPS

Allen Browne,

Thanks, I could not find that information in any of the three Microsoft
Office / Access books or even in a 4th book on Visual Basic 6. I wish
someone would print a book that had all the bells and whistles included...
but with sites like this, its great to know that my questions and answers can
help others like me as well.

I appreciate your time and support. I've posted one other question after
making a few corrections to the same code. Please reference a new question
posted today as well if you have time.

Thanks Again.
 

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