Verify existence of DB property

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

Guest

I am using a custom DB property to control an expiration date of a demo
version of an Access app. In order to avoid errors, though, I must first
check to see if the property exists (before I attempt to set its value).

Currently, I am enumerating the entire properties collection by looping
through numerically to see if any ...<Property#>.Name matches the name of the
property. Would it be better to do this: If IsNull
(CurrentDB.Properties("ABC").Name) Then...

Is there any simpler/better way to just check to see if it exists?
 
Trying to refer to a property that doesn't exist will raise an error (3270,
if memory serves) that you can trap.
 
Brian said:
I am using a custom DB property to control an expiration date of a
demo version of an Access app. In order to avoid errors, though, I
must first check to see if the property exists (before I attempt to
set its value).

Currently, I am enumerating the entire properties collection by
looping through numerically to see if any ...<Property#>.Name matches
the name of the property. Would it be better to do this: If IsNull
(CurrentDB.Properties("ABC").Name) Then...

That last approach won't work, because it will raise an error (3270,
IIRC) if the property "ABC" doesn't exist.
Is there any simpler/better way to just check to see if it exists?

What I usually do is refer to the property and trap the error if it
doesn't exist. For example:

On Error Resume Next
varABC = CurrentDb.Properties("ABC").Value
Select Case Err.Number
Case 0
' The property exists
Case 3270 ' ** If I remember right -- check this
' The property doesn't exist
Case Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End Select
On Error GoTo Err_Handler ' reset to normal error-handler
 
Thanks.

Dirk Goldgar said:
That last approach won't work, because it will raise an error (3270,
IIRC) if the property "ABC" doesn't exist.


What I usually do is refer to the property and trap the error if it
doesn't exist. For example:

On Error Resume Next
varABC = CurrentDb.Properties("ABC").Value
Select Case Err.Number
Case 0
' The property exists
Case 3270 ' ** If I remember right -- check this
' The property doesn't exist
Case Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
End Select
On Error GoTo Err_Handler ' reset to normal error-handler

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
You could always bounce off on error resume next


On Error Resume Next
testStr = Null
testStr = backendDB.Properties("AllowSpecialKeys") 'will set it to a value if found if not it will be null
If Nz(testStr) = "" Then
Set prp = backendDB.CreateProperty("AllowSpecialKeys", dbBoolean, keyShift)
backendDB.Properties.Append prp
Else
backendDB.Properties("AllowSpecialKeys") = keyShift 'Use Access Special Keys
End If
 
Back
Top