Opening a Form from a different database

G

Guest

I have a Main Switchboard and would like to open a Form from a different
database.
I try to do this with a command button and it looks like the following:

Private Sub OpenVendedorForm_Click()
On Error GoTo Err_OpenVendedorForm_Click

Dim stDocname As String
Dim stLinkCriteria As String

stDocname = "C:\\cps208/sales.mdb/salespersonal"
DoCmd.OpenForm stDocname, , , stLinkCriteria

Exit_OpenVendedorForm_Click:
Exit Sub

Err_OpenVendedorForm_Click:
MsgBox Err.Description
Resume Exit_OpenVendedorForm_Click

End Sub

I get an error message that the Form cannot be found; but the string
"C:\\cps208/sales.mdb/salespersonal" is correct.
Can someone tell me how I can open a form which is in a different database?
Thanks
Klaus
 
A

Arvin Meyer [MVP]

It's a bit more complex than that. First create a Public Subroutine in a
standard module (taking care not to name the module the same as the
routine), in the first database (the one that contains the form):

Public Sub OpenSalesPersonal()
DoCmd.OpenForm "SalesPersonal"
End Sub

Now set a reference in the second database. Code Window: Tools >>>
References. Change the type to MDB then enter:

C:\cps208\sales.mdb

Notice how my path is different than yours? Yours is incorrect. Only
backslashes in paths. Only forward slashes in URLs

Now for your command button. Code is really simple:

Private Sub OpenVendedorForm_Click()
OpenSalesPersonal
End Sub

I've taken the names from your post. Hopefully they are spelled correctly.
If not, you'll need to fix that.
 
G

Guest

Thanks Arvin

Just your part "create a Public Subroutine in a standard module " I don't
understand.
In this I am totally new and have no idea what you mean. Is there any
example somewhere or could you explain this part a bid more detailed?
Thanks
Klaus
 
G

Guest

Dear Arvin,
I think I explain what I did so far to see if that was correct:

* In my sales DB I created a module with the name "saleshelp" - the module
contains the following:
Option Compare Database

Public Sub OpenSalesPersonal()
DoCmd.OpenForm "salespersonal"
End Sub

* In my main DB I put on the command button on click:
Private Sub OpenVendedorForm_Click()
OpenSalesPersonal
End Sub

Now I am searching for the: "Now set a reference in the second database.
Code Window: Tools >>>References. Change the type to MDB then
enter:C:\cps208\sales.mdb
Where do I find in my main DB the "Code Window: Tools >>>References"?

I hope I am not going on your nervs with this questions and thank you for
the help.
Klaus
 
A

Arvin Meyer [MVP]

In your main database, go to any code window. It doesn't matter which one.
The one that has the command button code will be fine. On the menu bar look
for the Tools item and drop it down, where you will see References, as the
first sub item.

Open the References dialog box.

Click the Browse button.

Change the Files of Type combo to the first item:
Microsoft Access Databases (*mdb)

Navigate to your database with the form you want to open.

Double-click it or select it and press Open

Close and save the module and go to the form with the button.

Click the button and everything should work.
--
Arvin Meyer, MCP, MVP
http://www.datastrat.com
http://www.mvps.org/access
http://www.accessmvp.com
 
G

Guest

Hello Arvin
I went into my main database. What do you mean with a "code window"? - If I
open Tools in the menu bar I don't find "references".
Maybe I understand the "code window" wrong - please tell me how to open a
code window (stupid I know, but only question marks are coming out of my
head)?
Thanks
Klaus
 
G

Guest

OK, I believe you ment the VB code window for my main database.
I opend Tools>>>>References >>>> Browse = an add reference window opens with
a look-in: System32 - files. I changed the file type into "Microsoft Office
Access Database mdb and see the files.
From here I am lost
Please tell me how to carry on.
Thanks
Klaus
 
G

Guest

Yes, I was stupid or somehow blocked. It's working now and thanks again for
your help.
Klaus
 

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

Similar Threads


Top