Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Call Access form procedure from Excel form

Status
Not open for further replies.

ktwclark

Computer
Feb 3, 2002
1
0
0
US
I'm having a bit of a problem calling an procedure on a
Microsoft Access Form from an Excel Form. I've created the
Access object, opened the database containing the form,
displayed the form, autofilled some textboxes, but I can't seem
to get the correct syntax to call one of the access form's
procedures. This is what I have so far:

I have an Access form called InputData
It has a textbox called txtData

From within an Excel form I have this code:

Dim appAccess As Object 'Microsoft Access database object
'Create an instance of Microsoft Access
Set appAccess = CreateObject("Access.Application")
With appAccess
'Open the database "ABC.mdb"
.OpenCurrentDatabase "C:\My Documents\ABC.mdb"
'Open the "InputData" form.
.DoCmd.OpenForm "InputData"
.Forms![InputData]!txtData.SetFocus
.Forms![InputData]!txtData.Text = "Demo Data"
'Call Procedure "StoreData" on Access Form "InputData"
HELP!
End With

 
Replies continue below

Recommended for you

Assuming that the StoreData() procedure is invoked using a command button (if not, add a command button, give it a name, have it call the form's procedure - you can set the button to Visible=No if you want)...

Them inside your with loop:
.Forms![InputData]!cmdMyButton.Click()

That should work.
 
I am also having a problem calling a procedure from excel


Private Sub CommandButton1_Click()
'Microsoft Access database object
Dim appAccess As Object
Dim en As String
Dim r As Integer
Dim c As Integer
Set myrange = Range("A10:A60")
'Create an instance of Microsoft Access
Set appAccess = CreateObject("Access.Application")
'Open the database "RDS.mdb"
appAccess.OpenCurrentDatabase "M:\rds.mdb"
'Open the "ESU form" form.
appAccess.docmd.OpenForm "ESU form"
appAccess.Forms![ESU form]!txtEN.SetFocus
r = 1
c = 1
For r = r To 50
en = myrange.Cells(r, c)
If en = "" Then
r = "50"
Else
appAccess.Forms![ESU form]!txtEN = en
appAccess.Forms![ESU form]!cmdMyButton.Click()
End If
Next r
'close access
appAccess.Application.Quit acEXIT
Set appAccess = Nothing
End Sub

AFTER I entered appAccess.Forms![ESU form]!cmdMyButton.Click() I get a compiler error expected =
I am new with VBA please help if I use = true then I get a runtime error 2465

please help
Todd
 
Status
Not open for further replies.
Back
Top