Connecting Tech Pros Worldwide Forums | Help | Site Map

Repository for common forms across multiple .mdb's

Expert
 
Join Date: Oct 2008
Location: Cedar City, Utah, USA
Posts: 104
#1: 3 Weeks Ago
I have several forms and code subroutines that are common across the many databases that I support. The solution my predecessor, who built many of these databases, used was to put a copy of the forms and code into each database.

Over time, I've pulled most of the duplicated code out of the front-end applications and consolidated it into an .mdb used as a shared code repository. The code repository is then referenced in each application that it's needed in. This works great for code - not so great for forms.

Does anyone know of a way that I can do the same thing with the duplicate forms?
best answer - posted by ADezii
I liked the concept proposed by topher23 so much, that I created code contained within a single Form that will:
  • Open an Office File Dialog filtered for Access Databases only (*.mdb).
  • Once a Database is selected, a List Box on the Form (MultiSelect = Extended, RowSourceType = 'Value List') is populated with the Names of all Forms residing in the External Database.
  • Simply select 1 or several Forms as so desired.
  • Click on a Command Button to Import the Selected Form(s) into the Current Database.
  • For any Project you create, include this Form Template to automate the Form Import process.
  • If anyone is actually interested, let me know and I'll post the code.

ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,225
#2: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


Quote:

Originally Posted by topher23 View Post

I have several forms and code subroutines that are common across the many databases that I support. The solution my predecessor, who built many of these databases, used was to put a copy of the forms and code into each database.

Over time, I've pulled most of the duplicated code out of the front-end applications and consolidated it into an .mdb used as a shared code repository. The code repository is then referenced in each application that it's needed in. This works great for code - not so great for forms.

Does anyone know of a way that I can do the same thing with the duplicate forms?

If you use the same Code Routines across many Databases, then you should consider creating a Library Database(s) (*.mda). These Databases contain Code Modules shared by a number of Applications and they relieve you from having to create and maintain a separate Version of a Function in each Database where it is called. To reference these Library Databases:
  1. Tools
  2. References
  3. Browse
  4. Select "Add-ins (*.mda)"
  5. Locate your Library Database
  6. OK
Expert
 
Join Date: Oct 2008
Location: Cedar City, Utah, USA
Posts: 104
#3: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


Right. If you read a bit closer you'll see that's exactly what I've already done. Originally, I named the file .mda, but I decided that the name was confusing as the database wasn't exactly an add-in, but a code repository, or library. When I hear library, I think books, so I don't use the term for db's. Sorry for the confusion there. Anyway, Access will reference the file as an add-in whether you name it .mda or .mdb, it doesn't really care.

The point is, is there any way to do it with forms? I looked into creating a true .mda add-in, complete with system tables and registry entries, but all indications are that simple forms still wouldn't work properly. Or am I reading too much into it, and creating an add-in is the way to go?
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,886
#4: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


I'm not sure if it could even be done with an add-in as I think forms need to be stored locally in a database. However, since I'm not sure I'll put out a call to some of our experts to see if anyone has any ideas.

Mary
missinglinq's Avatar
Moderator
 
Join Date: Nov 2006
Location: Richmond, Virginia USA
Posts: 3,002
#5: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


I agree with Mary's assessment here! You're referencing code in libraries, but forms have to physically be present in a database. I think the closest you can come would be to have a database where you stored these forms and simply import a copy into you db that is currently under development.

Linq ;0)>
Expert
 
Join Date: Jul 2009
Location: KY
Posts: 253
#6: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


Quote:

Originally Posted by missinglinq View Post

I agree with Mary's assessment here! You're referencing code in libraries, but forms have to physically be present in a database. I think the closest you can come would be to have a database where you stored these forms and simply import a copy into you db that is currently under development.

Linq ;0)>

I also agree.
I have a tool I use right now that acts as a centralized DB for all my forms, references, and modules, which also houses all my DBs. So when I deploy any new DBs or make a changes to a "Shared" module, reference, or form, I can push out the changes through my central DB. But bottom line, I still have to store them in a DB.

-AJ
ADezii's Avatar
Expert
 
Join Date: Apr 2006
Location: Philadelphia
Posts: 5,225
#7: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


I liked the concept proposed by topher23 so much, that I created code contained within a single Form that will:
  • Open an Office File Dialog filtered for Access Databases only (*.mdb).
  • Once a Database is selected, a List Box on the Form (MultiSelect = Extended, RowSourceType = 'Value List') is populated with the Names of all Forms residing in the External Database.
  • Simply select 1 or several Forms as so desired.
  • Click on a Command Button to Import the Selected Form(s) into the Current Database.
  • For any Project you create, include this Form Template to automate the Form Import process.
  • If anyone is actually interested, let me know and I'll post the code.
Expert
 
Join Date: Oct 2008
Location: Cedar City, Utah, USA
Posts: 104
#8: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


Adezii, I like your thinking. You may even be able to set it up so you can push the forms from one database out to a completely different database using another list box. That would be some serious automation.

Well, as for my original question, I was able to slap together a sort of work-around. I used CreateObject to initiate my "library" in another instance of Access. For some reason, it hadn't occurred to me previously that CreateObject could be used to create more Access instances. Anyway, referencing that instance, I was able to pull up the form I wanted, manipulate the recordsource, and even populate data in the form from the original database based on data entered into and displayed on the form in the other instance. In my "calling" form, I used a loop to make sure the second form was closed before the calling subroutine killed the instance.

I won't post this code, since I figure it's pretty straightforward for anyone with a bit of experience and the ability to look up CreateObject in the help file (plus it's really ugly right now, as I've only just been testing it and I'm not certain it won't break).

Even more fun, I used a function that I found on the webs a while back to hide the second access window while still displaying the form (form has to be set to popup in order for this to work properly), making the transition between different instances of Access totally invisible to the user.

For anyone interested, this is the code that hides the Access window.
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Private Declare Function IsWindowVisible Lib "User32" (ByVal hWnd As Long) As Long
  4. Dim dwReturn As Long
  5.  
  6. Const SW_HIDE = 0
  7. Const SW_SHOWNORMAL = 1
  8. Const SW_SHOWMINIMIZED = 2
  9. Const SW_SHOWMAXIMIZED = 3
  10.  
  11. Private Declare Function ShowWindow Lib "User32" (ByVal hWnd As Long, _
  12.      ByVal nCmdShow As Long) As Long
  13.  
  14. Public Function pfnAccessWindow(Optional Procedure As String, Optional SwitchStatus As Boolean, Optional StatusCheck As Boolean) As Boolean
  15. If Procedure = "Hide" Then
  16.     dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
  17. End If
  18. If Procedure = "Show" Then
  19.     dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
  20. End If
  21. If Procedure = "Minimize" Then
  22.     dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMINIMIZED)
  23. End If
  24. If SwitchStatus = True Then
  25.     If IsWindowVisible(hWndAccessApp) = 1 Then
  26.         dwReturn = ShowWindow(Application.hWndAccessApp, SW_HIDE)
  27.     Else
  28.         dwReturn = ShowWindow(Application.hWndAccessApp, SW_SHOWMAXIMIZED)
  29.     End If
  30. End If
  31. If StatusCheck = True Then
  32.     If IsWindowVisible(hWndAccessApp) = 0 Then
  33.         pfnAccessWindow = False
  34.     ElseIf IsWindowVisible(hWndAccessApp) = 1 Then
  35.         pfnAccessWindow = True
  36.     End If
  37. End If
  38. End Function
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,762
#9: 3 Weeks Ago

re: Repository for common forms across multiple .mdb's


Nice work Topher.

I've never really played much with different types of Access files, but I hed a question the other day about MDEs and thought I'd experiment a little.

When I read this I decided I'd do the same with MDAs (this afternoon). Fun isn't it. I just wish I'd bothered earlier. It's only recently that I've done much work creating new databases and requiring much of the functionality to be available that I had previously developed, but this is certainly worth knowing about. I'm sure I'll play more soon.
Reply