An omission in the VB automation type library is any method of creating a new gallery. Still, as you'll see, there is a work-around.
Don't be misled, the Document function:
Function Open(Path As String, AccessMode As Integer, Password As String) As Integer
...opens a Catalogue, not a Gallery so ideally your Galleries need to exist beforehand (maybe not, see below *).
Likewise, the function:
Function New(Path As String) As Integer
...opens a new Catalogue not a new Gallery.
Note that using this latter function's syntax as per documentation throws an "argument not optional" error despite supplying the correct data, e.g. PortObj.New("D:\MISC\change.fdb"). Despite this the Catalogue file does get created but the error message is odd (this was observed when running from the IDE with no error trapping and not from a compiled exe which might be a reason).
You also get an "argument not optional" error with the Open function if you pass an empty string because no password is set. It seems you must have a password - if only for the level you want to work at:
PortObj = PortObj.Open("D:\MISC\change.fdb", 4, "admin")
PortObj = PortObj.Open("D:\MISC\change.fdb", 4, "")
...fails. Go figure!
Lest you wonder, if you create a new Catalogue file (PortObj.New) and do a Count (PortObj.Count) you get the answer 1. Why? Well there is an in-build default Gallery which doesn't show in the Galleries list (Ctrl+Shift+G). It seems it is only used if there are no existing Galleries - plus if you alter the layout of the default you'll be asked to name and save it (no default name is supplied). So! There is a roundabout way to create a new Gallery! (Note a .Count in Portfolio numbers from one and not zero (like many build-in VB Counts)
All very well but what happens if the Catalogue is set to open a saved Gallery at start - you won't get a default Gallery to work with. Instead choose an existing Gallery - any one (including the default if a new Catalogue) - and then use the function:
Function SaveAs(sNewName As String) As Integer
... to 'create' a new Gallery with the name passed in sNewName. Intuitive - not! Note also that the Gallery.Save and Gallery.SaveAs functions are only available with the v5 automation library.
Try this with a newly created catalogue file:
'assumes a project reference to "Portfolio_V5"
Dim PortObj As Portfolio_V5.Document
Dim PortGal As Gallery
Private Sub Command1_Click()
Set PortObj = New Portfolio_V5.Document
Set PortGal = PortObj.Gallery(PortObj.GetGalleryIndexFromName(PortObj.GetActive))
... your Gallery list should now show a single Gallery called 'NewGallery'. You can do similar in an existing Catalogue. Either way you get a new Gallery of that name, which will inherit the look/customisation of the Gallery it is based on. Important to note that you now need to do further scripting to set the right options for the Gallery and set the correct records to associate with it.
Question: Creating Galleries with VB [FAQ00176.htm]
Last Update:- 31 May 2006
Site and articles © Mark Anderson 2001-2007 - Visit my home page