Verify existence of DB property

B

Brian

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?
 
D

Douglas J Steele

Trying to refer to a property that doesn't exist will raise an error (3270,
if memory serves) that you can trap.
 
D

Dirk Goldgar

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
 
B

Brian

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)
 

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