error opening form based on record nr.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pierkes
    New Member
    • Feb 2013
    • 64

    error opening form based on record nr.

    Hi,

    I had an embedded macro that i converted to VBA code...now, it does not work anymore...

    My situation:

    I have 2 forms;

    - frm_trajecten - list of clients
    based on a Query: Q_trajecten which is based on a table tbl_trajecten
    - frm_traject_det ails - details of a client
    based on query Q_trajecten_det ails which is based on table tbl_trajecten

    in tbl_trajecten (and both queries i have a field [ID_traject]

    On frm_trajecten i have a field [tr_naam_traject] with a hyperlink with the following code;

    Code:
    Private Sub tr_naam_traject_Click()
    On Error GoTo tr_naam_traject_Click_Err
    
            On Error Resume Next
        If (Form.Dirty) Then
            DoCmd.RunCommand acCmdSaveRecord
        End If
        If (MacroError.Number <> 0) Then
            Beep
            MsgBox MacroError.Description, vbOKOnly, ""
            Exit Sub
        End If
        On Error GoTo 0
        DoCmd.OpenForm "frm_traject_details", acNormal, "", "[ID_traject]=" & Nz(ID_traject, 0), , acDialog
        If (Not IsNull(ID_traject)) Then
            TempVars.Add "CurrentID", ID_traject
        End If
        If (IsNull(ID_traject)) Then
            TempVars.Add "CurrentID", Nz(DMax("[ID_traject]", Form.RecordSource), 0)
        End If
        DoCmd.Requery ""
        DoCmd.SearchForRecord , "", acFirst, "[ID_traject]=" & TempVars!CurrentID
        TempVars.Remove "CurrentID"
    
    
    tr_naam_traject_Click_Exit:
        Exit Sub
    
    tr_naam_traject_Click_Err:
        MsgBox Error$
        Resume tr_naam_traject_Click_Exit
    
    End Sub
    When executing the code i actually opens the form frm_traject_det ails, which is good.

    However, when i try to close the form i get an error message on the line:

    Code:
    If (Not IsNull(ID_traject)) Then
            TempVars.Add "CurrentID", ID_traject
    Saying "tempvars can only store data, they cannot store objects"

    It stops the code", goes back to the form frm_trajecten after which nothing works anymore (it is stuck)

    How can this be corrected ?

    Thanks for helping me !
    Pierkes
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3662

    #2
    pierkes,

    Try this for your errored line:

    Code:
    TempVars.Add "CurrentID", ID_traject.Value
    I have run across this, too, and it seems TempVars always wants to see the control as the control itself, rather than the value (which is the default in every other location in VBA).

    Hope this helps.

    Comment

    • Pierkes
      New Member
      • Feb 2013
      • 64

      #3
      Hi Twinnyfo,

      Thank you very much for replying. Tried your suggestion and it now returns from the frm_traject_det ails to frm_trajecten but the the program does not react to anything anymore.

      The only thing i can then do is stop the program and restart it...


      Any suggestions on how to proceed?

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        I've split the thread at this point and selected TwinnyFo's answer as best answer to the original question.

        The subsequent question/issue that has developed is located at:

        Comment

        Working...