Full Version: Pass Data In 1 Control From Db1 To Db2
UtterAccess Forums > Microsoft® Access > Access Forms
Knuckles
Good morning UA world,

I am trying to pass the data contained in a single text box to another database. Here is the actual scenario.
A user logs into DB1 with a password and the users empID is stored in a textbox on the login form.
When the user clicks the "GO" button DB2 opens.
I want to copy the data from the textbox in DB1 to the main form of DB2 then close DB1.

I was hoping to do something on the open event of the main form in DB2.
Me.txtEmpID = DB1!Forms!frmLogin!txtEmpID
docmd.Quit (DB1)

The thought process is there but I do not know how to execute it. Thanks in advance for any help.

Knuckles
theDBguy
Hi. How exactly were you opening DB2 from DB1? If you're using Shell to execute MSACCESS.EXE with a path argument to DB2, then you can use the /cmd switch to pass the value to DB2. Just a thought...
Knuckles
Good morning,

I was using this and it works fine. Just need to grab that field before I close DB1

Private Sub cmdDB2_Click()
Dim FilePath As String
FilePath = "E:\MyServer\DB2.accdb"

Application.FollowHyperlink FilePath
DoCmd.Quit
End Sub
theDBguy
You could try the following:

CODE
Public Function GetValueFromDB1() As Variant
Dim app As Object

Set app = GetObject("Path to DB1")

GetValueFromDB1 = app.Forms!FormName.ControlName

Set app = Nothing

End Function

Hope that helps...
Knuckles
Thanks, that worked perfectly!

how do I close DB1?
theDBguy
I think you could use:

app.Quit
Knuckles
won't that close Access and both databases?
Knuckles
I just left that that line in and it worked.

Private Sub cmdDB2_Click()
Dim FilePath As String
FilePath = "E:\MyServer\DB2.accdb"

Application.FollowHyperlink FilePath
DoCmd.Quit

Thanks for the help DBGuy.

Knuckles
theDBguy
Hi. You're welcome. Glad to hear you got it to work. Good luck with your project.
Knuckles
DBGuy,

Just a quick note...

It worked in terms of opening and closing the database however it did not recognize that DB1 was already open. It would open a second session which would in turn placed the database in a locked state and other users could not connect.

I resolved the problem by creating a table with one field to capture the user and then referenced it from DB2 via a link.

Thanks for your help.

K
theDBguy
Hi K. Nice going! Thanks for the update.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.