' *********** code start *********** function changepropertyddl(stpropname as string, _ proptype as dao.datatypeenum, vpropval as variant) _ as boolean ' uses the ddl argument to create a property ' that only admins can change. ' ' current createproperty listing in access help ' is flawed in that anyone who can open the db ' can reset properties, such as allowbypasskey ' on error goto changepropertyddl_err
dim db as dao.database dim prp as dao.property
const conpropnotfounderror = 3270
set db = currentdb ' assuming the current property was created without ' using the ddl argument. delete it so we can ' recreate it properly db.properties.delete stpropname set prp = db.createproperty(stpropname, _ proptype, vpropval, true) db.properties.append prp
' if we made it this far, it worked! changepropertyddl = true
changepropertyddl_exit: set prp = nothing set db = nothing exit function
changepropertyddl_err: if err.number = conpropnotfounderror then ' we can ignore when the prop does not exist resume next end if resume changepropertyddl_exit end function
帮助本身的例子 function changeproperty(strpropname as string, _ varproptype as variant, varpropvalue as variant) as integer ' the current listing in access help file which will ' let anyone who can open the db delete/reset any ' property created by using this function, since ' the call to craeteproperty doesn't use the ddl ' argument ' dim dbs as database, prp as property const conpropnotfounderror = 3270
set dbs = currentdb on error goto change_err dbs.properties(strpropname) = varpropvalue changeproperty = true
change_bye: exit function
change_err: if err = conpropnotfounderror then ' property not found. set prp = dbs.createproperty(strpropname, _ varproptype, varpropvalue) dbs.properties.append prp resume next else ' unknown error. changeproperty = false resume change_bye end if end function ' *********** code end ***********