jpl458
jpl458

Reputation: 615

using autoexec to link tables prior to on open event

This question follows a previous question Form is ignoring the code in OnOpen event that was answered by Andre.

I have a form that is bound by a control that executes a query, so I can't use the onopen event to relink tables when the form is opened. I have created a function as follows:

Function AutolinkDB()
    Dim tdf As DAO.TableDef

    For Each tdf In CurrentDb.TableDefs
        ' check if table is a linked table
        If Len(tdf.Connect) > 0 Then
            tdf.Connect = "Connect String"
            tdf.RefreshLink
        End If
    Next

    ''' Andre edit: after relinking the tables, open the start form
    DoCmd.OpenForm "loginputFrm"
    ''' Andre edit

End Function

Next, I created an autoexec macro that looks like the following:

OpenForm
  Form Name loginputFrm
         View Form
  Filter Name
Where Condition
         Data Mode
  Window Mode  Normal
RunCode
  Function Name Autolink()

Problem is that the autolink does not execute the function, and app still asks for manual password.

Upvotes: 0

Views: 114

Answers (1)

Andre
Andre

Reputation: 27644

The only thing in your AutoExec macro should be

RunCode -> AutolinkDB()

(Note that you currently have Autolink() - typo?)

Nothing else. At the end of AutolinkDB(), open your start form with DoCmd.OpenForm.

Otherwise the form will be opened first, and ODBC data accessed.

Upvotes: 1

Related Questions