By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,482 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,482 IT Pros & Developers. It's quick & easy.

Boolean Field Properties.

P: n/a
Okay here is my problem. I have a table that is imported by the user and
then I need to add a boolean field to the table with Format Yes/No and the
Display Control as Check box. Here is what I have.
------------------------------------------------------------
Dim DB As DAO.Database, MyTableDef As TableDef
Dim MyField As Field

Set DB = CurrentDb()
Set MyTableDef = DB("Client Copy")
Set MyField = MyTableDef.CreateField("Selection", dbBoolean)

MyTableDef.Fields.Append MyField
------------------------------------------------------------
Any help is very much appriciated.

-Andrew

--
Message posted via http://www.accessmonster.com
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Try:
MyField.CreateProperty("DisplayControl", dbInteger, CInt(acCheckBox))

The routine below is what I use to set the property if it already exists, or
create and set the property if it doesn't. For this example, you would call
it like this:
Call SetPropertyDAO(MyField, "DisplayControl", dbInteger,
CInt(acCheckBox))

----------------------code starts----------------
Public Function SetPropertyDAO(obj As Object, strPropertyName As String, _
intType As Integer, varValue As Variant, Optional strErrMsg As String) As
Boolean
On Error GoTo ErrHandler
'Purpose: Set a property for an object, creating if necessary.
'Arguments: obj = the object whose property should be set.
' strPropertyName = the name of the property to set.
' intType = the type of property (needed for creating)
' varValue = the value to set this property to.
' strErrMsg = string to append any error message to.

If HasProperty(obj, strPropertyName) Then
obj.Properties(strPropertyName) = varValue
Else
obj.Properties.Append obj.CreateProperty(strPropertyName, intType,
varValue)
End If
SetPropertyDAO = True

ExitHandler:
Exit Function

ErrHandler:
strErrMsg = strErrMsg & obj.Name & "." & strPropertyName & _
" not set to " & varValue & ". Error " & Err.Number & " - " &
Err.Description & vbCrLf
Resume ExitHandler
End Function

Public Function HasProperty(obj As Object, strPropName As String) As Boolean
'Purpose: Return true if the object has the property.
Dim varDummy As Variant

On Error Resume Next
varDummy = obj.Properties(strPropName)
HasProperty = (Err.Number = 0)
End Function
---------------------code ends--------------------

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Andrew Smith via AccessMonster.com" <fo***@nospam.AccessMonster.com> wrote
in message
news:79******************************@AccessMonste r.com...
Okay here is my problem. I have a table that is imported by the user and
then I need to add a boolean field to the table with Format Yes/No and the
Display Control as Check box. Here is what I have.
------------------------------------------------------------
Dim DB As DAO.Database, MyTableDef As TableDef
Dim MyField As Field

Set DB = CurrentDb()
Set MyTableDef = DB("Client Copy")
Set MyField = MyTableDef.CreateField("Selection", dbBoolean)

MyTableDef.Fields.Append MyField
------------------------------------------------------------
Any help is very much appriciated.

-Andrew

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.