Re: Sources for query parameters



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
2. document variable? don't think I've ever heard that term
[quoted text clipped - 54 lines]

Petr

--
HTH

Dale Fye

Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/Forums.aspx/access-queries/200907/1

.



Relevant Pages

  • Re: Fields?
    ... Again, rather than jumping into the more advanced methods, start with the ... beginner articles and use the Forms toolbar. ... > downloaded the sample Word document and Access database zipfile from ... I have placed both the form and the database in the ...
    (microsoft.public.word.formatting.longdocs)
  • Re: Word and databases
    ... but in a database interface. ... maintain a word document, which would be printed, binded, and distributed. ... This became a major inconvenience for the data entry staff, ... The third column lists the designations. ...
    (microsoft.public.office.developer.automation)
  • Re: PHP Passing Variables Between Pages and Security
    ... utility and the data was then saved in the database. ... check if it was actually a Word document, and the command-line utility ...
    (comp.lang.php)
  • Re: Database Properties : Date Created vs DateCreated
    ... The database object has a Properties collection, ... ByVal varPropValue As Variant) ... Dim prp As DAO.Property ... Set prp = db.CreateProperty ...
    (microsoft.public.access.tablesdbdesign)
  • Re: Fields?
    ... I am sure Charles was starting to think I ... downloaded the sample Word document and Access database zipfile from ... I have placed both the form and the database in the ... When I click the Command button for "Update New" I expect that the data ...
    (microsoft.public.word.formatting.longdocs)

Loading