Problems with Auto_Open not running subroutine

be_savvy

New Member
Joined
Sep 23, 2014
Messages
6
I have a subroutine that compiles and runs successfully when run manually. I'm trying to set up Auto_Open so that it is run on open, but it doesn't seem to be working. It is definitely kicking off the Auto_Open, as the MsgBox displays properly, but it does not seem to run my getFunctionDetails subroutine. My code is below:

Code:
Private Sub Auto_Open()

MsgBox "HELLO WORLD!"
Call getFunctionDetails


End Sub


'  Subroutine getFunctionDetails
'
'  Populate function and parameter descriptions based on FUNC_DTL table
'
Sub getFunctionDetails()
On Error GoTo dbferror
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim vArgDescr() As Variant
Dim vArgCounter As Integer


vArgCounter = 1
Set db = DBEngine.OpenDatabase("C:\INSERT_DIRECTORY_NAME_HERE\Database\INSERT_DB_NAME_HERE.accdb", dbReadOnly)


Set rs = db.OpenRecordset("SELECT * FROM FUNC_DTL_V", dbReadOnly)
rs.MoveFirst
While Not rs.EOF
    If rs!PRMTR_ID = 1 Then
        ReDim vArgDescr(1 To rs!PRMTR_CT) As Variant
    End If
    
    If rs!PRMTR_ID = 0 Then
        Application.MacroOptions Macro:=rs!FUNC_NM, Description:=rs!CODE_FORMAT, Category:=rs!UD_CAT, ArgumentDescriptions:=vArgDescr
        vArgCounter = 0
    Else
        vArgDescr(vArgCounter) = rs!CODE_FORMAT
    End If


    vArgCounter = vArgCounter + 1
    rs.MoveNext
Wend
 
rs.Close
db.Close
Exit Sub


dbferror:
   getdbfver = "DBF: error " & Err.Description
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)
Move Hello World to just below the dim in GetFunctionDetails then progressively move it lower and lower to see where it is halting.
 
Upvote 0
Amazing! Thanks, Blade Hunter. Turns out the MacroOptions are not available until the workbook is open, so that's where it was failing. I added 'Workbooks.Add' before calling my getFunctionDetails subroutine and it worked like a charm.

Thanks again!
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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