473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Library Databases

PhilOfWalton
1,430 Expert 1GB
Suppose I have a main database and several referenced library databases. Lets's call them MainDb, Lib1Db and Lib2Db.

Assuming I am in the main Db and I want a count of the forms in both Lib1Db & Lib2Db, how do I "address" them.

I can't see that CodeProject.AllForms.Count will work as Access won't know which CodeProject to use.

Thanks

Phil
Dec 29 '17 #1
4 1728
gnawoncents
214 100+
Phil,

There is likely a more elegant way to do this, but I couldn't find it. Try the code below and please ignore any typos as I tested the code against a database with a different name then modified the code per your naming conventions.

Expand|Select|Wrap|Line Numbers
  1. Private Sub btnCountForms_Click()
  2.  
  3. Dim db As Database
  4. Dim cnt As Container
  5. Dim doc As Document
  6. Dim intMain As Integer
  7. Dim intLib1 As Integer
  8. Dim intLib2 As Integer
  9.  
  10. 'Count the number of forms in the main/current database and save as intMain
  11. intMain = CurrentProject.AllForms.Count
  12.  
  13. 'Count the number of forms in Lib1Db database and save as intLib1
  14. Set db = OpenDatabase("YOUR Lib1Db DATABASE PATH HERE")
  15.  
  16. For Each cnt In db.Containers
  17.     If cnt.Name = "Forms" Then
  18.         For Each doc In cnt.Documents
  19.             intLib1 = intLib1 + 1
  20.         Next doc
  21.     End If
  22. Next cnt
  23.  
  24. 'Count the number of forms in Lib2Db database and save as intLib2
  25. Set db = OpenDatabase("YOUR Lib2Db DATABASE PATH HERE")
  26.  
  27. For Each cnt In db.Containers
  28.     If cnt.Name = "Forms" Then
  29.         For Each doc In cnt.Documents
  30.             intLib2 = intLib2 + 1
  31.         Next doc
  32.     End If
  33. Next cnt
  34.  
  35. Set db = Nothing
  36.  
  37. End Sub
  38.  
Dec 29 '17 #2
NeoPa
32,556 Expert Mod 16PB
Hi Phil.

Gnawoncents pointed the way but there is a more straightforward approach to getting at the numbers they've found. My version includes databases that have a password just in case (Probably unlikely with a library database but can't hurt). I've worked on the basis that you have a routine to decrypt passwords called Decrypt(). I've also set intCount as a Form-level variable so it can be used by other code.
Expand|Select|Wrap|Line Numbers
  1. Private intCount As Integer
  2.  
  3. Private Sub btnCountForms_Click()
  4.     'Count the number of forms in the main/current database.
  5.     intCount = CurrentProject.AllForms.Count
  6.     intCount = intCount + _
  7.                CountForms(strPath:="YOUR Lib1Db DATABASE PATH HERE" _
  8.                         , strEncPW:="Optional Encrypted Password")
  9.     intCount = intCount + _
  10.                CountForms(strPath:="YOUR Lib2Db DATABASE PATH HERE" _
  11.                         , strEncPW:="Optional Encrypted Password")
  12. End Sub
  13.  
  14. 'CountForms() returns the number of forms in the database of strPath.
  15. '             If an encrypted password is passed then it's used.
  16. Private Function CountForms(strPath As String _
  17.                           , Optional ByVal strEncPW As String="") As Integer
  18.     Dim strConnect As String
  19.  
  20.     strConnect = Replace("MS Access;PWD=%PW;DATABASE=%DB" _
  21.                        , "%PW", Decrypt(strEncPW))
  22.     strConnect = Replace(strConnect, "%DB", strPath)
  23.     strConnect = Replace(strConnect, ";PWD=;", ";")
  24.     'To open a database with a password the 'optional' parameters are mandatory.
  25.     With OpenDatabase(dbName:=strPath _
  26.                     , Options:=False _
  27.                     , Read-Only:=True _
  28.                     , Connect:=strConnect)
  29.         CountForms = .Containers("Forms").Documents.Count
  30.         Call .Close()
  31.     End With
  32. End Function
Bear in mind, though this should work, it's really for illustrative purposes to show what can be done. You'll probably want to do things a little differently depending on your actual requirement for that value but this should point you in the right direction. Just as Gnawoncents' code did for me :-)
Dec 29 '17 #3
PhilOfWalton
1,430 Expert 1GB
Thanks for you very quick response. I tried to keep it simple- obviously a mistake.

The ultimate aim is to open all the Forms & Reports in Design View in Lib1Db & Lib2Db to get information on all their controls. I then need to build a table with database name, form name & information about the controls.

I have used the OpenDatabase "YOUR Lib2Db DATABASE PATH HERE") in the past, ans seem to end up with multiple copies of Access running and the only way to close them is with TaskManager.

I have a feeling that as I can open a library database Form using a function within the library database from the main database that the main database is "aware" of the library database.

So in Lib1Db = have this function
Expand|Select|Wrap|Line Numbers
  1. Function OpenFrm(FrmName, Optional Vew, Optional Filtr, Optional Whre, Optional Datmode, Optional WindMode, Optional Args)
  2.  
  3.     On Error GoTo OpenFrm_Error
  4.  
  5.     If IsMissing(Args) Then
  6.         Args = vbNull
  7.     End If
  8.  
  9.     DoCmd.OpenForm FrmName, Vew
  10.  
  11.     Exit Function
  12.  
  13. OpenFrm_Error:
  14.     If Nz(Args) = "Application Quit" Then
  15.         Resume Next
  16.     Else
  17.         Msgbox "Error " & Err.Number & " (" & Err.Description & ") in procedure OpenFrm of form " & FrmName
  18.     End If
  19.  
  20. End Function
  21.  
In the main Database debug window, typing OpenFrm "MyForm", AcDesign works fine, but what happens if both library databases have a "MyForm"

Phil
Dec 29 '17 #4
NeoPa
32,556 Expert Mod 16PB
In that case I don't know the answer. I don't even have such a database to play with (You could email me one if you like Phil).

OTOH if you go to the Object Browser in the VBAIDE (From Access press Alt-F11 then F2.) and drop down the list which normally says <All Libraries> then you should see a list of references which should include your library databases. If you select that in the Object Browser then you'll see below a list of all its classes and their properties. I didn't see a Forms collection when I looked :-(
Phil:
I tried to keep it simple- obviously a mistake.
That wasn't the mistake. The inaccuracy was the mistake. Simple is always good. It's not always easy to keep the focus in the right place while trying to simplify though.
Dec 29 '17 #5

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

Similar topics

4
by: mike | last post by:
Hi, I am trying to determine what the overhead is per database in SQL Server 2000 Standard. I have the option to put several customers in one database, or give each customer their own database....
6
by: Jonathon Blake | last post by:
All: I thought I had seen a python library/module that easily enabled one to read / write / create MSAccess databases a couple of years ago. Now, I can't find it, or any reference to such a...
15
by: grunar | last post by:
After some thought on what I need in a Python ORM (multiple primary keys, complex joins, case statements etc.), and after having built these libraries for other un-named languages, I decided to...
0
by: Peter | last post by:
When I issue call sqlj.install_jar('file:///f:/jars/mail.jar','MAIL'); I get the messages SQL4301N Java or .NET interpreter startup or communication failed, reason
4
by: Dirk Olbertz | last post by:
Hi there, I'm currently about to redesign a database which you could compare with a database for managing a library. Now this solution will not only manage one library, but 100 to 500 of them....
44
by: Jeff | last post by:
Hi I have a library mde that is used with some customer databases and I found out that another developer discovered it while doing some maintenance work on an old database for the same customer...
5
by: Lysander | last post by:
My collegue had to buy a new laptop that came with Office 2007 already installed. She had Access 2003 installed on top, in a different directory. None of our 2003 databases will run on her...
10
by: drumahh | last post by:
I have created a "library" Access Database. I "reference" this library file within another Microsoft Access database by using Tools->References->Browse-> File Name: (Libraryfile.accdb) Files of...
0
PhilOfWalton
by: PhilOfWalton | last post by:
I know a little about using Library databases, but have never messed around with Add Ins. Can someone explain the difference, and can you have an "Add In database" if so is it just a standard Db ...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.