Open a form from another database

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!!!!!!
 
D

Daniel Pineault

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.
 
G

GD

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?
 
G

GD

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top