473,406 Members | 2,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

Database Properties

NeoPa
32,556 Expert Mod 16PB
The following code, when added as a standard module, allows easy use and manipulation of the properties of a database :
Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. Option Explicit
  3.  
  4. Private Const conNoProp As Integer = 3270
  5. Private Const conVBToDB As String = "\2|3\3|4\4|6\5|7\6|5" & _
  6.                                     "\7|8\8|10\11|1\14|20\17|2"
  7.  
  8. 'SetProperty() requires that either intPType is set explicitly OR that
  9. '              varPVal has a valid value if a new property is to be created.
  10. Public Sub SetProperty(strPName As String _
  11.                      , varPVal As Variant _
  12.                      , Optional ByVal objVar As Object _
  13.                      , Optional intPType As Integer = -1)
  14.     Dim prpVal As DAO.Property
  15.  
  16.     Call SetObj(objVar)
  17.     If PropertyExists(strPName, objVar) Then
  18.         objVar.Properties(strPName) = varPVal
  19.     Else
  20.         If intPType = -1 Then intPType = DBVal(VarType(varPVal))
  21.         Set prpVal = objVar.CreateProperty(strPName, intPType, varPVal)
  22.         Call objVar.Properties.Append(prpVal)
  23.     End If
  24. End Sub
  25.  
  26. 'GetProperty() returns the value of the specified property if found.
  27. Public Function GetProperty(ByRef strPName As String, _
  28.                             Optional ByVal objVar As Object) As Variant
  29.     Call SetObj(objVar)
  30.     If PropertyExists(strPName, objVar) Then _
  31.         GetProperty = objVar.Properties(strPName)
  32. End Function
  33.  
  34. 'PropertyExists() returns True if the property exists and False if it doesn't.
  35. Public Function PropertyExists(ByRef strPName As String _
  36.                              , Optional ByVal objVar As Object) As Boolean
  37.     Dim varTest As Variant
  38.  
  39.     On Error GoTo ErrorHandler
  40.     Call SetObj(objVar)
  41.     PropertyExists = True
  42.     varTest = objVar.Properties(strPName)
  43.     Exit Function
  44.  
  45. ErrorHandler:
  46.     If Err <> conNoProp Then
  47.         On Error GoTo 0
  48.         Resume
  49.     End If
  50.     PropertyExists = False
  51. End Function
  52.  
  53. 'DelProperty() deletes the property if it exists.
  54. Public Sub DelProperty(ByRef strPName As String _
  55.                      , Optional ByVal objVar As Object)
  56.     Call SetObj(objVar)
  57.     If Not PropertyExists(strPName, objVar) Then Exit Sub
  58.     Call objVar.Properties.Delete(strPName)
  59. End Sub
  60.  
  61. 'SetObj() sets objVar to CurrentDb() if it's not already set.
  62. Private Sub SetObj(ByRef objVar As Object)
  63.     If objVar Is Nothing Then Set objVar = CurrentDb()
  64. End Sub
  65.  
  66. 'DBVal() returns the value of the Type that is used in DAO
  67. '  from the VBA equivalent.
  68. Private Function DBVal(intVBVal) As Integer
  69.     Dim intX As Integer
  70.  
  71.     intX = InStr(1, conVBToDB, "\" & intVBVal & "|")
  72.     DBVal = Val(Mid(conVBToDB, intX + Len(intVBVal) + 2))
  73. End Function
If it is required to determine which named properties are already available for a database then the following code, run from the Immediate Pane of the VBA IDE window, will show them for you :
Expand|Select|Wrap|Line Numbers
  1. Set db = CurrentDb : For Each prp in db.Properties : ?prp.Name : Next prp
Jan 11 '12 #1
0 7686

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Michael Bourgon | last post by:
Here's something I found a few months ago, and it seems to come in handy pretty often, so I figured I'd share. Disclaimer: you are modifying a SYSTEM TABLE. This may not work in the next...
1
by: Phil S | last post by:
I am working with Access 2000. For several versions of Access, I have relied on clicking File --> Database Properties to check on the path for the current database (very handy when I might have...
21
by: Peter Nurse | last post by:
I have just upgraded to SQL Server 2005 from SQL Server 2000. In Microsoft SQL Server Management Studio, when I click on database properties, I receive the following error:- Cannot resolve the...
17
by: Sam Malone | last post by:
I am trying to get details from a database. I really want to use only native VS.NET managed code "stuff" (just cuz I want to) and avoid any interop stuff. So, I'm trying to do this without using...
2
by: Guvnor | last post by:
Hello there, I have about 30 sql servers runnign multiple databases amd i need to audit them so what i want to do is to log onto each server and then maybe export the database properties into an...
0
by: Skeptical | last post by:
Hello, We have MS SQL Server 2000 and recently we found out that right clicking on a database and selecting properties would lock up the enterprise manager. We have 80 Databases 4 GB Memory 2...
7
by: Jim Devenish | last post by:
I wish to control which users can and cannot alter the toolbars. The opening popup window invites them to login. Immediately after this, I have the code: ...
1
innesaji
by: innesaji | last post by:
What is the difference between the different "Build Actions" in the properties panel on my database files?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.