VB to Access via DDE

  • Thread starter Thread starter Jonathan
  • Start date Start date
J

Jonathan

Hello all,

Is there any way for a VB application to communicate with an Access
application via DDE? I want to be able to send text box data to Access
forms, click buttons and menu bars from an external application.



Thanks in advance,

Jonathan
 
Jonathan,

Yes, the process is called "automation". The following is referred to as
"early binding". It is the easiest, and most functional because it gives you
access to Intellisense, but it is version-dependent. If you want version
independence, you have to use "late binding".

Add a reference to the Access type library

Dim acc As Access.Application
Dim db As DAO.Database

Set acc = New Access.Application
acc.OpenCurrentDatabase "path to database.mdb"
Set db = acc.CurrentDb

acc.Forms!frmMyForm!txtSomeTextbox = "abc"

acc.Quit acQuitSaveNone
acc.CloseCurrentDatabase
Set db = Nothing
Set acc = Nothing

To use "late binding"...
Dim acc As Object
Dim db As DAO.Database

Set acc = CreateObject("Access.Application")

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
Graham
This looks good. Can you navigate menu bars and click buttons this way?

Jonathan
 
Jonathan,

Once you get at the Access application object, you can do anything you want.
Just preface everything with acc (if that's what your Access application
object is called).

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
---------------------------
 
Jonathan said:
Hello all,

Is there any way for a VB application to communicate with an Access
application via DDE? I want to be able to send text box data to Access
forms, click buttons and menu bars from an external application.



Thanks in advance,

Jonathan

Yes.

There are plenty of examples in both the VB and MSAccess help files. Lookup
"dde functions poke".

Note: not all examples will be specific to MSAccess, (usually Excel), but
they will work with any application that supports DDE.

-ralph
 
Maybe I'm missing something obvious but what combination of commands do you
use to click a button on a form??

Also I found that I had to execute acc!DoCmd.OpenForm "Form1" before I could
but anything in a text box.

Jonathan
 
You don't click the button: you call the procedure (or macro) that's defined
for the click event. Assuming the button is named MyButton, you'd do
something like:

Call acc.Forms("Form1").MyButton_Click

Note that this requires that you change the declaration from Private Sub
MyButton_Click() to Public Sub MyButton_Click().
 
Duhh! Thanks Doug!

Jonathan


Douglas J. Steele said:
You don't click the button: you call the procedure (or macro) that's defined
for the click event. Assuming the button is named MyButton, you'd do
something like:

Call acc.Forms("Form1").MyButton_Click

Note that this requires that you change the declaration from Private Sub
MyButton_Click() to Public Sub MyButton_Click().
 
Douglas J. Steele said:
You don't click the button: you call the procedure (or macro) that's defined
for the click event. Assuming the button is named MyButton, you'd do
something like:

Call acc.Forms("Form1").MyButton_Click

Note that this requires that you change the declaration from Private Sub
MyButton_Click() to Public Sub MyButton_Click().


In pure VB:

Form1.MyButton.Value = True

That command will cause the click event to execute. How does that
fare in Access? Using the appropreate syntax for Access, would it
have a similar effect? (No change to Public event needed....)

LFS
 
Larry Serflaten said:
In pure VB:

Form1.MyButton.Value = True

That command will cause the click event to execute. How does that
fare in Access? Using the appropreate syntax for Access, would it
have a similar effect? (No change to Public event needed....)

Doesn't look like it.

It raises an error 2448:


You can't assign a value to this object.
* The object may be a control on a read-only form.
* The object may be on a form that is open in Design view.
* The value may be too large for this field


I tried in both Access 97 and Access 2003.
 
Larry Serflaten said:
"Douglas J. Steele" <NOSPAM_djsteele@NOSPAM_canada.com> wrote
In pure VB:

Form1.MyButton.Value = True

That command will cause the click event to execute. How does that
fare in Access?

Value is really flaky in Access, from what I remember. For example, you
can't set a text box's Value (six of one) unless that control has the focus,
but you can set its Text (half-dozen of another) all day long from anywhere.
 
not true, text is the flaky one

Pieter


Jeff Johnson said:
Value is really flaky in Access, from what I remember. For example, you
can't set a text box's Value (six of one) unless that control has the
focus, but you can set its Text (half-dozen of another) all day long from
anywhere.
 
The Value property for an Access control is not flaky at all, it's simply
that people coming from VB to Access expect it to be the same as it is in
VB, it isn't.

It's quite simple you can get the Value property of a control when the
control has focus, you can get the Text property at any time the control is
loaded.
 
Good grief I'm really losing it, I'll try again.

Replace Value with Text and vice versa in the post below.
 
not really, it's the predecessor
and still AFAIK the core/origin of automation (?)
that said, automating Notus Lotes/ms word et al was flaky as hell back in
Access 1.1/2.0 when there was no other way <g>

Pieter
 
That's a bit like saying the travois is a predecessor to the automobile.



--

Terry Kreft


"Pieter Wijnen"
<it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace
..with.norway> wrote in message
 
Where do you think they got the design for the Robin Reliant, Terry? :-)
 
"Pieter Wijnen"
<it.isi.llegal.to.send.unsollicited.mail.wijnen.nospam.please@online.replace
..with.norway> wrote in message
not really, it's the predecessor
and still AFAIK the core/origin of automation (?)
that said, automating Notus Lotes/ms word et al was flaky as hell back in
Access 1.1/2.0 when there was no other way <g>

Pieter

For completeness Terry is correct. The two technologies share only
'concepts' in common. Internal implementation is unique and separate for
both.

-ralph
 

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

Back
Top