Re: Sources for query parameters
- From: "Dale_Fye via AccessMonster.com" <u43991@uwe>
- Date: Mon, 06 Jul 2009 11:21:59 GMT
Petr,
You can create new properties for the database, and store values in them.
Database properties are retained in the application, and can be addressed
directly, as you indicate in your example.
Public Sub SetProperty(PropertyTitle As String, PropertyValue As Variant)
Dim prp As Property
On Error Resume Next
Select Case VarType(PropertyValue)
Case vbString
Set prp = CurrentDb.CreateProperty(PropertyTitle, dbText,
PropertyValue)
Case vbInteger, vbLong
Set prp = CurrentDb.CreateProperty(PropertyTitle, dbLong,
PropertyValue)
Case Else
MsgBox "SetProperty only execepts strings and integer values"
End Select
CurrentDb.Properties.Append prp
If Err.Number = 3367 Then
CurrentDb.Properties(PropertyTitle).Value = PropertyValue
End If
End Sub
Public Function GetProperty(PropertyTitle As String) As Variant
On Error Resume Next
GetProperty = CurrentDb.Properties(PropertyTitle).Value
If Err.Number <> 0 Then
MsgBox Err.Number, Err.Description
GetProperty = Null
end if
End Function
HTH
Dale
Petr Danes wrote:
Hi Dale,
1. global variable: Not directly
Rats. Oh well.
2. document variable? don't think I've ever heard that term
Sorry, that was a bit of schizophrenia on my part. They're used in Word,
rather than Access, where you can put field definitions into your document
that retrieve values from these variables. I develop in several Office
applications and occasionally get fuddled about which object model contains
what.
The syntax in Word is:
ActiveDocument.Variables.Add "MyVar", "ABC"
Once executed, the variable becomes part of the Word document and its value
remains set when the document is saved, unlike globals or locals. Values may
be read or changed through code, and read in the document via fields, or
deleted through code. They are not directly visible anywhere in the UI.
The Access object model also includes a document object, but it's not the
same thing as the Word document and it does not have a Variables collection
among its properties.
3. custom document property. Can you give an example?
You bet. Here're a couple of functions that set and get one such property.
The comments are in Czech, the code refers to a few global variables and
includes a bit of error handling to deal with the property not yet created,
but you should get the drift. If not, post back and I'll step you through
them. They function similarly to the Word document variables, where you can
create, set, read and delete them from code, and their values remain set
when the Db is closed. Also, they are visible through the UI in the main
database window, under File / Properties, Custom tab. I don't know if they
can be accessed directly by the SQL in a query, that was actually my
original question. None of my experiments in that direction have yielded any
positive results.
Petr
Public Function GetRootFolder$()
' Podíváme se jestli existuje uživatelská vlastnost nazvaná Zdroj. Jestli
ano, pokusíme se vylovit obsah.
' Když tato vlastnost neexistuje, vytvoøíme ji.
' Používá se jako koøenová složka zdrojových dat. Když nic neexistuje,
nabídneme složku ve které žije databáze.
On Error Resume Next
GetRootFolder =
CurrentDb.Containers(1).Documents(Uzivatelske).Properties(RootFolderPropName)
If Err = 3270 Then
GetRootFolder = CurrentDb.Name
GetRootFolder = Left$(GetRootFolder, InStrRev(GetRootFolder,
vbBackSlash))
CurrentDb.Containers(1).Documents(Uzivatelske).Properties.Append
CurrentDb.Containers(1).Documents(Uzivatelske).CreateProperty(RootFolderPropName,
dbText, GetRootFolder)
End If
End Function
Public Sub SetRootFolder(a$)
' Uloží koøenovou složku dat. Pøiplácne zpìtné lomítko na konec, jestli tam
už není.
On Error Resume Next
CurrentDb.Containers(1).Documents(Uzivatelske).Properties(RootFolderPropName)
= a & IIf(Right$(a, 1) = vbBackSlash, vbNullString, vbBackSlash)
If Err = 3270 Then
CurrentDb.Containers(1).Documents(Uzivatelske).Properties.Append
CurrentDb.Containers(1).Documents(Uzivatelske).CreateProperty(RootFolderPropName,
dbText, a & IIf(Right$(a, 1) = vbBackSlash, vbNullString, vbBackSlash))
End Sub
1. global variable: Not directly[quoted text clipped - 54 lines]
2. document variable? don't think I've ever heard that term
Petr
--
HTH
Dale Fye
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200907/1
.
- Follow-Ups:
- Re: Sources for query parameters
- From: Dale_Fye via AccessMonster.com
- Re: Sources for query parameters
- References:
- Sources for query parameters
- From: Petr Danes
- Re: Sources for query parameters
- From: Dale_Fye via AccessMonster.com
- Re: Sources for query parameters
- From: Petr Danes
- Sources for query parameters
- Prev by Date: Re: Calculation Error in Select Query
- Next by Date: Re: Sources for query parameters
- Previous by thread: Re: Sources for query parameters
- Next by thread: Re: Sources for query parameters
- Index(es):
Relevant Pages
|
Loading