Results 1 to 7 of 7
  1. #1
    equestrian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    15

    DoCmd.OpenForm with OpenArgs not working as expected

    I am using Access 2007

    I have the following tables:

    tblUnitsBuilt
    UnitBuiltPK
    UnitFK
    BuilderFK
    ReasonBuiltFK


    DateBuilt
    SerialNumber

    tblReasonBuilt
    ReasonBuiltPK
    Reason

    tblBuiltForCustomer
    BuiltForCustomerPK
    CustomerFK
    UnitBuiltFK

    On my form (frmUnitBuilt) the user enters the reason built. If it is built for a customer (ReasonBuiltFK=2) then a form opens to enter the customer it is built for (frmBuiltForCustomer). The user enters the customer for whom the unit was built. The user then closes the form. There is an entry put in the tblBuiltForCustomer. However, the value for UnitBuiltFK is empty.

    On frmUnitBuilt I have:
    Code:
    Private Sub cboReasonBuilt_AfterUpdate()
    If Me.cboReasonBuilt = 2 Then
    DoCmd.OpenForm "frmBuiltForCustomer", , , "UnitBuiltFK= " & Me.UnitBuiltPK
    End If
    End Sub
    On frmBuiltForCustomer I have:
    Code:
    Private Sub Form_Load()
        If Not IsNull(Me.OpenArgs) Then
        Me![UniteBuiltFK] = Me.OpenArgs
        End If
    End Sub
    Thank you for any help you can offer.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Does an 'e' belong in UniteBuiltFK?

    Is the form set to open to a new record? If not, then the code will change existing record.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    equestrian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    15
    No. The "e" did not belong on UnitBuiltFK. I took it off, and I am having the same problem. The form is set to open to a new record. When I check the table a record is created it just does not have a value in UnitBuiltFK.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Try code in the Current event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    In your Docmd.Openform statement, you are not giving the OpenArgs argument any data. The OpenArgs argument is the 7th argument, and you are only using 4.

    What follows is cut-and-paste from the A2010 help, but A2007 is the same:

    The OpenForm method carries out the OpenForm action in Visual Basic.
    Syntax

    expression.OpenForm(FormName,
    View, FilterName, WhereCondition, DataMode,
    WindowMode, OpenArgs)


    expression A variable that represents a
    DoCmd object.




  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Good catch John_G.

    The code should be like:

    DoCmd.OpenForm "frmBuiltForCustomer", , , , , , Me.UnitBuiltPK
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    equestrian is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    15
    You were absolutely right. That was the problem I was having. Thank you very much.

    Also, the value I was passing was a number not a string. So, I fixed that.

    On frmUnitBuilt I have:
    Code:
    Private Sub cboReasonBuilt_AfterUpdate()
    If Me.cboReasonBuilt = 2 Then
    DoCmd.OpenForm "frmBuiltForCustomer", , , , , , Me.UnitBuiltPK
    End If
    End Sub
    On frmBuiltForCustomer I have:
    Code:
    Private Sub Form_Load()
    Dim id As Integer
     id = CInt(Me.OpenArgs)
        If Not IsNull(Me.OpenArgs) Then
        Me![UnitBuiltFK] = id
        End If
    End Sub
    Thank you so much

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

Similar Threads

  1. Docmd.openform (date) and (text)
    By sovereign in forum Forms
    Replies: 3
    Last Post: 06-19-2015, 08:07 AM
  2. DoCmd.Close OpenArgs NOT WORKING
    By clchris_80 in forum Access
    Replies: 1
    Last Post: 01-19-2013, 09:07 PM
  3. DoCmd.OpenForm Syntax Error
    By alsoto in forum Forms
    Replies: 3
    Last Post: 02-29-2012, 01:14 PM
  4. What actually happens at docmd.openform
    By Beorn in forum Programming
    Replies: 4
    Last Post: 01-05-2011, 02:19 PM
  5. DoCmd.OpenForm Modification
    By alsoto in forum Forms
    Replies: 6
    Last Post: 05-01-2009, 07:28 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