-2

All is explained in the title.

I need to be able to run a macro in word that opens up an access database.

braX
  • 11,506
  • 5
  • 20
  • 33
  • Possible duplicate of https://stackoverflow.com/questions/9024816/access-shell-cmd-open-mdb – Sam Feb 14 '19 at 22:14
  • 1
    What have you looked into so far? What version of Access? Are you just trying to open the file in Access? or just read records from the tables? – Profex Feb 14 '19 at 22:16
  • @Profex I've tried doing hyperlinks i think they're called but they didnt work. Its just the latest version of Office 365, just trying to open the db, thats all, nothing else – Ritchie McGrath Feb 14 '19 at 22:19

1 Answers1

1

If you want to open and manipulate Access object, consider:

Public Sub OpenDB()
Dim db As Access.Application
Set db = New Access.Application
db.OpenCurrentDatabase "C:\My Documents\db2.mdb"
db.Application.Visible = True 'optional
'code to manipulate Access
End Sub

If you just want to open an Access file and then let user interact as normal, following works for me:

'Shell function requires literal quote marks in the target filename string argument, apostrophe delimiters fail, hence the quadrupled quote marks
Shell SysCmd(acSysCmdAccessDir) & "MSAccess.exe " & """" & "C:\My Documents\dbname.accdb" & """", vbNormalFocus
June7
  • 19,874
  • 8
  • 24
  • 34
  • To be able to use the Access object library, it will have to be added to the references in VBA. **Tools-->References-->"Microsoft Access XX.0 Object Library"** – Profex Feb 14 '19 at 22:27
  • Right. And I just read that the file is Office 365. No idea if code will work with Office 365. – June7 Feb 14 '19 at 22:30
  • yeah, that was my next question...is access actually installed on the PC, or is it just online? What happens when you double click the database file now? – Profex Feb 14 '19 at 22:32
  • Thank you, it is installed on the PC. The code just comes up "compile error, sub or function not defined" – Ritchie McGrath Feb 14 '19 at 22:38
  • Just got it to run there, it was the reference that needed added. You are literally an absolute life saver folks! Thank you so much!!! – Ritchie McGrath Feb 14 '19 at 22:41