K
keyur
hi
i have a macro, that will save and close the file once
executed. I want to open and access form just before it
closes. this is what i found from VBA help
"The following example opens a Microsoft Access database
from another application through Automation and then opens
a form in that database.
You can enter this code in a Visual Basic module in any
application that can act as a COM component. For example,
you might run the following code from Microsoft Excel,
Microsoft Visual Basic, or Microsoft Access.
When the variable pointing to the Application object goes
out of scope, the instance of Microsoft Access that it
represents closes as well. Therefore, you should declare
this variable at the module level.
' Include the following in Declarations section of module.
Dim appAccess As Access.Application
Sub DisplayForm()
' Initialize string to database path.
Const strConPathToSamples = "C:\Program " _
& "Files\Microsoft Office\Office\Samples\"
strDB = strConPathToSamples & "Northwind.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strConPathToSamples
' Open Orders form.
appAccess.DoCmd.OpenForm "Orders"
End Sub
"
but when i put this in Excel macro it shows me an
error "user-defined type not defined" for "Dim appAccess
As Access.Application", which i have in declaration.
since i quite new to VBA i might have just missed to
change something in the code.
thanks for any help.
i have a macro, that will save and close the file once
executed. I want to open and access form just before it
closes. this is what i found from VBA help
"The following example opens a Microsoft Access database
from another application through Automation and then opens
a form in that database.
You can enter this code in a Visual Basic module in any
application that can act as a COM component. For example,
you might run the following code from Microsoft Excel,
Microsoft Visual Basic, or Microsoft Access.
When the variable pointing to the Application object goes
out of scope, the instance of Microsoft Access that it
represents closes as well. Therefore, you should declare
this variable at the module level.
' Include the following in Declarations section of module.
Dim appAccess As Access.Application
Sub DisplayForm()
' Initialize string to database path.
Const strConPathToSamples = "C:\Program " _
& "Files\Microsoft Office\Office\Samples\"
strDB = strConPathToSamples & "Northwind.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strConPathToSamples
' Open Orders form.
appAccess.DoCmd.OpenForm "Orders"
End Sub
"
but when i put this in Excel macro it shows me an
error "user-defined type not defined" for "Dim appAccess
As Access.Application", which i have in declaration.
since i quite new to VBA i might have just missed to
change something in the code.
thanks for any help.