Goto a form in MS ACCESS

  • Thread starter Thread starter Dennis Cheung
  • Start date Start date
D

Dennis Cheung

I need a marco in Excel to go to a form in MS ACCESS
Form: Frm001
DataBase: c:\data\Sales.mdb
the form was opened already.

Dennis
 
Dennis,

If what you want is a macro that opens a form from within Excel try this.


Dim appAccess As Access.Application

Sub DisplayForm()

FindRef = ActiveCell 'when it open the form it will look for this in the
first field
'if you don't want to look for anything
omit this line

On Error GoTo Error_Handler

' Initialize string to database path.
Const strConPathToSamples = "YOUR PATH\DATABASEFILENAME.mdb"

' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strConPathToSamples

' Open form.
DoCmd.OpenForm "FORMNAME", acNormal, "", "", , acNormal
DoCmd.FindRecord FindRef, acEntire, False, , False, acCurrent, True
'omit this line if you don;t want to find a particular record & just
want to open
the form

Exit Sub

Error_Handler:

appAccess.Visible = False
MsgBox "No data found"
appAccess.Quit acQuitSaveNone 'change to save or prompt where necessary

End

End Sub
--

You'll need to amend it, filename, formname, etc to your needs and make sure
the error handling meets your needs.

_______________________
Naz,
London
 
Back
Top