Call Function in Another Database

  • Thread starter Thread starter Todd Shillam
  • Start date Start date
T

Todd Shillam

Can you call a function in another Microsoft Access database. I know you can
call a function within the same database file; however, I want to know if
you can in a different .mdb file. If so, what is the correct syntax within
an event procedure's code?

Thanks in advance,

Todd
 
Todd,

The simple way to explain this is by way of an example:

Create 2 databases DB1 & DB2

In DB1 create a public sub called ShowMessage with the
code below:

Public Sub ShowMessage()
MsgBox "HELLO"
End Sub

and in DB2: in the form select Tools, References in a
form, browse to DB1 (making sure you select All Types for
the file type), create a form and a command button with
the following code:

Private Sub Command0_Click()
db1.ShowMessage
End Sub

This is how you do it.

Alastair MacFarlane
 
I got this part to work; however, I would like to know what the syntax
is to call a function from a form control's event in another database
on a form.

For exampe, I have a command button on a form in one database:

'db1.mdb (Database Name)
'frm1 (Form's Name)

Public Sub Command0_Click()

'Do This....

End Sub


I would like to call the form's Command0_Click event (function) in
another database.

Thanks,

Todd
 
Ok...my workaround was to create a new module, declaring a public
function that would call a form object's event (function) within the
same database:

'frm1 (Name of Form)
Public Sub Command0_Click()

MsgBox "db1 Message"

End Sub

Then I created a new module within the same database:

'modShowMessage (Name of Module)
Public Sub ShowMessage()

Form_frm1.Command0_Click

End Sub

Afterwards, I opened the second database (db2.mdb), and I changed the
code for the form button's OnClick event, as follows:

Private Sub Command0_Click()

db1.ShowMessage

End Sub

Of course I added the reference as noted earlier. In closing this
approached worked; however, I am wondering if I can reference the
function directly. In closing, thanks for your reply--at least I got
this far.

Best regards,

Todd
 
Back
Top