Remove or Delete a User-defined Property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Can someone help me with creating and deleting user-defined properties? If
you can point me to a site with information on how to do this, I would
appreciate it. I have looked in Visual Basic Help and search this site, but
couldn't find anything.

Thanks in advance,

Arlene
 
Hi Arlene

Hmm. Not something we see requested every day.

There's a really old article here with several examples:
Custom Database Properties
at:
http://allenbrowne.com/ser-09.html
A quick look suggestions that it's all still relevant though.

There is a more recent example here:
Printer Selection Utility - Users assign printers to reports
at:
http://allenbrowne.com/AppPrintMgt.html
The code in the sample database creates a custom property on the report to
remember which printer to use for that report. (This allows the user to
assign one of their printers to the report, not one of the developers which
could have been done at design time.)

Finally, this code sets the property if it exists, and creates and sets it
if it does not exit.

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
 
hi,
Can someone help me with creating and deleting user-defined properties? If
you can point me to a site with information on how to do this, I would
appreciate it. I have looked in Visual Basic Help and search this site, but
couldn't find anything.

Private m_CurrentDb As DAO.Database
Private m_MyProperty As String

Public Property Get CurrentDbC As DAO.Database

If m_CurrentDb Is Nothing Then
Set m_CurrentDb = CurrentDb
End If

Set CurrentDbC = m_CurrentDb

End Property

Public Property Get MyProperty() As String

MyProperty = m_MyProperty

End Property

Public Property Let MyProperty(NewValue As String)

m_MyProperty = NewValue

End Property


mfG
--> stefan <--
 
Hi Allen,

Thanks so much! I'll take a look at the links and see if I can get get my
form working. I wasn't finding anything helpful in my searches, so I really
appreciate your help as always!

Arlene
 
Back
Top