Monday, June 29, 2009

Change the properties of ms access database dynamically

We can set the properties of mdb dynamically.

We can set the Startup Form, Title, Application Icon, hide the DB Window, prevent the use of special keys etc

Private Sub Form_Open(Cancel As Integer)
'setting up start up properties
Call SetStartupProperties
End Sub


Sub SetStartupProperties()
Const DB_Text As Long = 10
Const DB_Boolean As Long = 1
Dim intX As Integer
Dim i As Integer

intX = ChangeProperty("AppTitle", DB_Text, "TEST")
intX = ChangeProperty("AppIcon", DB_Text, "E:\Viji\Samples\Icons\LOGO.bmp")
CurrentDb.Properties("UseAppIconForFrmRpt") = 1
Application.RefreshTitleBar

ChangeProperty "StartupForm", DB_Text, "Customers"
ChangeProperty "StartupShowDBWindow", DB_Boolean, False
ChangeProperty "StartupShowStatusBar", DB_Boolean, False
ChangeProperty "AllowBuiltinToolbars", DB_Boolean, False
ChangeProperty "AllowToolbarChanges", DB_Boolean, False
ChangeProperty "AllowShortcutMenus", DB_Boolean, False
ChangeProperty "AllowFullMenus", DB_Boolean, False
ChangeProperty "AllowBreakIntoCode", DB_Boolean, False
ChangeProperty "AllowSpecialKeys", DB_Boolean, False
ChangeProperty "AllowBypassKey", DB_Boolean, False

End Sub



[CODE]
Function ChangeProperty(strPropName As String, varPropType As Variant, varPropValue As Variant) As Integer
Dim dbs As Object, prp As Variant
Const conPropNotFoundError = 3270
Set dbs = CurrentDb
On Error GoTo Change_Err

dbs.Properties(strPropName) = varPropValue
ChangeProperty = True
Change_Bye:
Exit Function
Change_Err:
If Err = conPropNotFoundError Then ' Property not found.
Set prp = dbs.CreateProperty(strPropName, _
varPropType, varPropValue)
dbs.Properties.Append prp
Resume Next
Else ' Unknown error.
ChangeProperty = False
Resume Change_Bye
End If
End Function
[/CODE]

No comments:

Post a Comment