Update variable in another database

  • Thread starter Thread starter Morgan
  • Start date Start date
M

Morgan

Hi

I have a MS Access DB that i use to process some global
variables. At a certain point in the process i would
like to open another Access DB and pass some values to
one of its forms and then have that form do some
processing.

So far i can open the second db ok but the problem is
then updating a control on a form in the second db.

I have tried using the DoCmd.OpenForm command in the
first database to open the form in the second db followed
by the [Forms]![Formname]![controlname] = valueabc
however it errors out because the form does not appear in
the forms collection of the first db.

I know that i can achieve a solution by writing the
valueabc out to a txt file and then have the second db
reference the text file however I am sure there must be a
way to pass a variable value between instances of Access.

Any help will be greatly appreciated.

Cheers
Morgan
 
Morgan,

I assume you are opening the 2nd db using automation, something like:

' In 1st db
dim rAppAcc As Access.Application
Set rAppAcc = New Access.Application
rAppAcc.OpenCurrentDatabase "2ndDb"
rAppAcc.DoCmd ' etc...

If so, you have at least two alternatives:

1. Use the Run method. Steps:
* Make a Public Function in your 2nd db to do what you want
* Use Run to call it in the 1st:

rAppAcc.Run "YourFn", Arg1, Arg2, ... ,Arg30

2. Work with the form directly. In the 1st db:

Dim rFrm as Access.Form
rAppAcc.DoCmd.OpenForm "YourForm"
Set rFrm = rAppAcc.Forms("YourForm")
rFrm.txtSomeName.Value = "abc"
...
Set rFrm = Nothing ' Always cleanup when done

Alternative 1 is your safest bet. I haven't personally tested
Alternative 2, but it should work.

-Ken
 
Back
Top