Open access form from spread sheet

jcaptchaos2

Well-known Member
Joined
Sep 24, 2002
Messages
1,032
Office Version
  1. 365
Platform
  1. Windows
I posted this in the excel forum and probably should have posted it here,
I have this code that is very close but don't understand why the access database and form open and then close right away, looking for some advice.

Code:
Sub OpenAccess()


    Dim LPath As String
    Dim LCategoryID As Long

    'Path to Access database
    LPath = "N:\Fishbowl Databases\Labor Collection Min.accdb"
    
    'Open Access and make visible
    Set oApp = CreateObject("Access.Application")
    oApp.Visible = True
    
    'Open Access database as defined by LPath variable
    oApp.OpenCurrentDatabase LPath
    
    'Open form called CLOSECASTOPFRM
    oApp.DoCmd.OpenForm "CLOSECASTOPFRM"
    oApp.Visible = True


End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Ok I got this to work but it is not opening the form, it does open the database and the main form that opens when the database is manually opened. I would like it to open the "op10edit" form.

Code:
Sub OpenAccess2()
Dim ac As Object
On Error Resume Next
Set ac = GetObject(, "Access.Application")
If ac Is Nothing Then
Set ac = GetObject("", "Access.Application")
ac.OpenCurrentDatabase "N:\Fishbowl Databases\Labor Collection Min.accdb"
ac.UserControl = True
ac.App.DoCmd.OpenForm "op10edit"
End If
AppActivate "Microsoft Access"
End Sub
 
Upvote 0
First off

Change this line:
ac.App.DoCmd.OpenForm "op10edit"

to this

ac.DoCmd.OpenForm "op10edit"

Second, put the

ac.UserControl = True

line AFTER the last line where you want to control because that particular line severs the link between the variable and the object. So, after that line you will want to use

Set ac = Nothing
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top