Open a form from another database

  • Thread starter Thread starter GD
  • Start date Start date
G

GD

How would I open a form from a different database via a macro? Can it be
done within RunApp, or is there another step?

The other database's path is S:\HQ
Common\DC_Finance\DATA_ANALYSIS\PAYBACKS\CM-DM Downloads.mdb

The form name is frmCMLabelsDataEntry.

Thanks!!!!!!
 
Using some automation (Read the Access VBA Help articles on
"GetObject Method" and "CreateObject Method" for more information) you can
achieve this. Try something like

Function OpenExDdForm(sDb As String, sForm As String)
On Error GoTo Error_Handler
Dim appAccess As Access.Application
' Create new instance of Microsoft Access.
Set appAccess = CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase sDb
appAccess.Visible = True
' Open the form.
appAccess.DoCmd.OpenForm sForm
'...do what ever you want

'When we are done clean up our variables.
Set appAccess = Nothing

If Err.Number = 0 Then Exit Function

Error_Handler:
MsgBox "MS Access has generated the following error" & vbCrLf & vbCrLf &
"Error Number: " & _
Err.Number & vbCrLf & "Error Source: OpenExDdForm" & vbCrLf & "Error
Description: " & _
Err.Description, vbCritical, "An Error has Occured!"
Exit Function
End Function

Then you'd call it:
OpenExDdForm("S:\HQ Common\DC_Finance\DATA_ANALYSIS\PAYBACKS\CM-DM
Downloads.mdb", "frmCMLabelsDataEntry")
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
Thanks, Daniel. But is code necessary? I'm not that familiar with it + my
boss wants it used as little as possible in our databases.

Right now I can open the target database with this in the RunApp command line:
"C:\Program Files\Microsoft Office\OFFICE11\MSACCESS.EXE" "S:\HQ Common\DC
Finance\DATA_ANALYSIS\PAYBACKS\CM-DM Downloads.mdb"

Is there no easy way to get it to open the specific form at that point?
 
Thanks for the thought, Steve, but I already have another form in that
database that needs to stay as the StartUp form. Any other thoughts?
 
Back
Top