Results 1 to 3 of 3
  1. #1
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Navigating Cross-References (2000+)

    I've been trying to set up a vanilla Function for navigating between cross-referenced records - fired on a TextBox Click Event (error handling excluded):<pre>Public Function GoToXRef(strSourceTable As String, strDataField As String)
    Dim cnn As ADODB.Connection
    Dim rstSnap As New ADODB.Recordset
    Dim lngPosition As Long
    Set cnn = CurrentProject.Connection
    rstSnap.Open strSourceTable, cnn, adOpenStatic
    rstSnap.Find strDataField & "=" & Screen.ActiveControl.Value
    lngPosition = rstSnap.AbsolutePosition
    DoCmd.GoToRecord , , acGoTo, lngPosition
    Set cnn = Nothing
    End Function</pre>

    The record navigation appears to work OK, but... Using <code>Application.Run GoToXRef("tblSomething", "FieldID")</code> produces Error Code 2517: ...Database can't find the procedure'.'. Wrapping it Event Procedure in <code>Dim appAccess as Access.Application</code> produces (eventually) Error Code 7952: You made an illegal function call. Would it be sensible to sweep away these Errors with Error Handling - or is there a better way?
    Gre

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Navigating Cross-References (2000+)

    The way to use Application.Run is

    Application.Run Procedurename, Arg1, Arg2, ...

    so in your situation:

    Application.Run "GoToXRef", "tblSomething", "FieldID"

  3. #3
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Navigating Cross-References (2000+)

    FWIW this amended code caters for the navigation taking place on other forms (such as Form/SubForm):<pre>Public Function GoToXRef(strSourceTable As String, strDataField As String, _
    strForm As String)
    Dim cnn As ADODB.Connection
    Dim rstSnap As New ADODB.Recordset
    Dim lngPosition As Long
    Set cnn = CurrentProject.Connection
    rstSnap.Open strSourceTable, cnn, adOpenStatic
    rstSnap.Find strDataField & "=" & Screen.ActiveControl.Value
    lngPosition = rstSnap.AbsolutePosition
    DoCmd.GoToRecord , strForm, acGoTo, lngPosition
    Set cnn = Nothing
    End Function</pre>

    Called with <code>Application.Run "GoToXRef", "tblSomething", "FieldID", "frmOverThere"</code>
    Gre

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •