This code won't execute... (1 Viewer)

ChazRab

New member
Local time
Today, 04:37
Joined
Oct 6, 2009
Messages
26
Opening a MS 2010 Access form from an Excel :

This code had no problem executing correctly in MS Office 2010. This code is not opening the form in Excel 2013. Here's the code:
[/code]
Sub ACCESSOPENFORM()
Dim ac As Object
Dim str As String
On Error Resume Next
Set ac = GetObject(, "Access.Application")
If ac Is Nothing Then
Set ac = GetObject("", "Access.Application")
ac.OpenCurrentDatabase "C:\Users\Charles\Desktop\PDOX DB.accdb"
ac.docmd.OpenForm "FORMVIEW"
ac.UserControl = True
Set ac = Nothing
End If
AppActivate "Microsoft Access"
ac.OpenCurrentDatabase "C:\Users\Charles\Desktop\PDOX DB.accdb"
ac.docmd.OpenForm "FORMVIEW"
[/code]
Comments:
In MS Access 2013 which I now have and like much better, Access opens and minimizes on the taskbar, but for some reason, the form FORMVIEW doesn't open and display over an Excel worksheet like it did very smoothly and flawlessly in Excel 2010. Why? Been trying to figure this out all day.
Need to get this working.

Thanks for anyone's help out there.
cr
 

Mihail

Registered User.
Local time
Today, 12:37
Joined
Jan 22, 2011
Messages
2,373
Sub ACCESSOPENFORM()
Dim ac As Object
Dim str As String
On Error Resume Next
Set ac = GetObject(, "Access.Application")
If ac Is Nothing Then

Set ac = GetObject("", "Access.Application")
ac.OpenCurrentDatabase "C:\Users\Charles\Desktop\PDOX DB.accdb"
ac.docmd.OpenForm "FORMVIEW"
ac.UserControl = True
Set ac = Nothing
End If
AppActivate "Microsoft Access"
ac.OpenCurrentDatabase "C:\Users\Charles\Desktop\PDOX DB.accdb"
ac.docmd.OpenForm "FORMVIEW"

So, in my opinion, ac will never be "Nothing" because is stetted just before the If statement.

In order to debug remove the On Error statement.
 

ChazRab

New member
Local time
Today, 04:37
Joined
Oct 6, 2009
Messages
26
...I finally got it to work. The code opened up Access and stopped at that point because this path, ac.OpenCurrentDatabase "C:\Users\Charles\Desktop\PDOX DB.accdb" pointed to a desktop icon, not the correct location of the file, which is located in
C:\Users\Charles\Documents\PDOX DB.accdb. Rather than change the path, I just created an AutoExec macro to open FORMVIEW every time Access opens, and it works great.

Thank again for all your help.

cr
Kingwood, Texas
 

Users who are viewing this thread

Top Bottom