What is happening when I enter this code for a split openargs?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeighW
    New Member
    • May 2012
    • 73

    What is happening when I enter this code for a split openargs?

    Hello all,

    I have this code running on a command button from the first form

    Code:
    Private Sub btn_OpenSubEvidence_Click()
    
    On Error GoTo Err_btn_OpenSubEvidence_Click
    
    Dim stDocName As String
    
    stDocName = "frm_SubEvidence"
        
    DoCmd.OpenForm stDocName, , , "[SubArgIDFK]=" & Me.[SubArgID], acFormAdd, , Me.[SubArgID] & "|" & Me.[Argument] & "|" & Me.[SubArgument]
    
    Exit_btn_OpenSubEvidence_Click:
        Exit Sub
    
    Err_btn_OpenSubEvidence_Click:
        MsgBox Err.Description
        Resume Exit_btn_OpenSubEvidence_Click
        
    End Sub
    And this code running in the on current event of the form which opens:

    Code:
    Private Sub Form_Current()
    If Me.NewRecord Then
    Me.[SubArgIDFK] = Split(Me.OpenArgs, "|")(0)
        Me.[Argument] = Split(Me.OpenArgs, "|")(1)
        Me.[SubArgument] = Split(Me.OpenArgs, "|")(2)
    End If
    End Sub
    The code has been entered so that when I open the form in Add Mode, the 3 fields I've entered copy across to the new record.

    The code actually works for adding a record, however, when you try and open the form in any other way, with a link criteria or the full version it displays no data, just the form header.

    The form which is opening is based on a query of a juntion table and the two linked tables. The same method works perfectly for a different form based on a query with a junction table and two linked tables but only has two split openargs using the same code (without the extra field).

    I believe the error message when clicking on a command button which opens the form via a link criteria specifies the second code shown above on the opening form as the problem.

    Is the code wrong when entering 3 fields for a openargs split? Or is it something else?

    Any help would be much appreciated,

    Leigh
  • LeighW
    New Member
    • May 2012
    • 73

    #2
    No worries I found out for some reason I had Data Entry set to YES in the form's properties. Much simpler than I thought. Embarrassing!

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Also, line #9 indicates to open the form in Data Entry mode anyway, and OpenArgs is only available to the Form_Open() procedure (Once that has completed the passed value is lost).

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        @ NeoPa.
        I believe that you are incorrect. OpenArgs are available as long as the form stay open, and no errors reset the application.
        I dont have time to doublecheck just now, however.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          That's strange Smiley. Is that for all versions?

          I don't like to give out false or unreliable information, but I'm not up to testing just now. Always good to correct me if I get it wrong though.

          Comment

          • LeighW
            New Member
            • May 2012
            • 73

            #6
            It seems to be working fine now since I've changed it. The filter and "acFormAdd" opens up the new record filtered to the ID of the previous form which the user can enter data in and then save. When linking back to the record it remains saved to that previous ID.

            I'm using Access 2003! Apparantly it works with both the Form_Current() and Form_Load() events.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32661

              #7
              Nice one boys :-)

              I just tested it and it certainly does keep it available now. I must have picked that up way back when I was using Access 2000 (or even 97 maybe).

              Comment

              Working...