Results 1 to 7 of 7
  1. #1
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99

    Open a second form using the OpenArgs

    Hi All,
    I have a command button on a form which will save the data and open a second form, and pass a parameter to the second form.
    Below is the code I tried:
    Code:
    Private Sub cmdSaveAndOpenNext_Click()
    DoCmd.Close acForm, Me.Name
        DoCmd.OpenForm "frm25-30-43FunctionalCheck-2", , , , , , Me.RepairID
    End Sub
    On the second form I have code like this:


    Code:
    Private Sub Form_Load()
        If Not IsNull(Me.OpenArgs) Then
        Me.RepairID = Me.OpenArgs
        Else: Me.RepairID = "Unknown"
        End If
        
    End Sub
    The problem is that when I click the command button and there's a runtime error 2467, sorry for my poor english i'd better not translate the description....
    Does anyone know what's wrong?
    Thanks in advance.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I would try it without the Else:, just multiline.
    Code:
     
    Private Sub Form_Load() 
      If Not IsNull(Me.OpenArgs) Then
         Me.RepairID = Me.OpenArgs 
      Else
         Me.RepairID = "Unknown"
      End If
     
    End Sub

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I hope RepairID is a text field/control.

  4. #4
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    Hi Rural,
    I removed the ":", it's the same.
    The RepairID is a textbox.
    After the runtime error the below line is highlighted
    Code:
     DoCmd.OpenForm "frm25-30-43FunctionalCheck-2", , , , , , Me.RepairID
    Could it be caused by closing the form first before open the second form?

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Absolutely! You cannot reference objects on a form *after* you close it. Just place the line of code *after* the OpenForm line. Good catch!

  6. #6
    blueraincoat is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2011
    Location
    Shanghai,CHN
    Posts
    99
    It works now.
    I tried that before, but I used the CTRL+X CTRL+V and the code automatically changed back to close first and then open.
    This time I typed the code and it works fine now...
    A little bit strange.

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Excellent! Thanks for posting back with your success.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. OpenArgs problems - FAO pbaldy/ruralguy
    By l3111 in forum Forms
    Replies: 22
    Last Post: 06-06-2011, 08:46 AM
  2. Showing OpenArgs in a Report.
    By SIGMA248 in forum Programming
    Replies: 2
    Last Post: 04-01-2011, 11:57 AM
  3. Opening a form with openargs and things
    By mwabbe in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:01 AM
  4. Replies: 9
    Last Post: 09-19-2010, 09:18 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums