How can I check a user-defined property in existence?

V

vvkl

In Form1's Load event, I want to know if a user-defined property which named
"EngineName" in existence,
how to do that ?

Thank you!
(I'm a chinese student ,If my question have syntax error,please excuse me!)
 
D

Douglas J. Steele

Try:

On Error Resume Next

strEngineName = CurrentDb.Properties("EngineName")

If Err.Number = 3270 Then
' Property doesn't exist
End If
 
M

Marshall Barton

vvkl said:
In Form1's Load event, I want to know if a user-defined property which named
"EngineName" in existence,
how to do that ?


You could use error handling to trap the situation where the
property does not exist.

On Error GoTo ErrorHandler
strEngine = Me.EngineName
. . .
Exit Sub

ErrorHandler:
Select Case Err.Number
Case ? 'Property not there
Me.Properties.Append CreateProperty("EngineName", . . .
Resume
Case . . .
Case Else
MsgBox Err.number & " - " & Err.Description
End Select
End Sub


Alternatively, you check to see if the property is in the
form's properties collection:

Dim prp As Property
Dim PropExists As Boolean
For Each prp In Me.Properties
If prp.Name = "EngineName" Then PropExists = True
Next prp

If Not PropExists Then
Me.Properties.Append CreateProperty("EngineName", . . .
End If
strEngine = Me.EngineName
 

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