Results 1 to 5 of 5
  1. #1
    nkenney is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Mar 2009
    Posts
    40

    Question Open form arguments

    Hi,



    I am having a problem and and hoping you can help. This is long, but I really need your help. I have a two forms once called "Customer" and the other called "Part" (this is not a subform). On the customer form I have a integer field (auto sequenced) called Custid.

    Code: On the customer form I have a button called "Add Part" and have the following code on the On-click event of my button.

    Private Sub Open_Part_Click()
    On Error GoTo Err_Add_Part_Click
    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "Part"
    stLinkCriteria = "[Custid]=" & Me![Custid]
    MsgBox (stLinkCriteria)
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    Exit_Add_Part_Click:
    Exit Sub
    Err_Add_Part_Click:
    MsgBox Err.Description
    Resume Exit_Add_Part_Click

    End Sub

    In the Part form, I have a "Custid" field (it is a foreign key). Here is my form On-Load event code:

    Private Sub Form_Load()

    numcustid = Forms!Customer.OpenArgs

    ' If numcustid > 0 Then
    ' DoCmd.GoToControl "Custid"
    ' DoCmd.FindRecord numcustid, , True, , True, , True
    ' Else
    ' Part.Custid = numcustid
    ' End If
    End Sub

    Now this works when I am enter the form and I have a part record. It goes to the correct record. However if no part already existed then the custid is empty and I can not fill it. I want to be able to add parts as well as edit and delete, so I need to somehow get the custid being past into the Part form and whenever I am adding be able to copy it to the cust id into the part form.

    If you got this far, I really, really appricate it. I really could use some ideas as to how to proceed. Any and all help is appriciate it.

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    To start, instead of applying a filter to the "Part" form by using the WhereCondition argument of the OenForm command, just pass the [CustID] in the OpenArgs argument:
    DoCmd.OpenForm "Part", , , , , , Me![Custid]

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Then in the OnLOad event of the "Part" form put:
    >>> WARNING <<< AIR CODE!!!
    Code:
    Private Sub Form_Load()
    
    If Not IsNull(Me.OpenArgs) Then
        '-- We're being passed the CustID
        Me.RecordsetClone.FindFirst "[numcustid] = " & Me.OpenArgs
        If Not Me.RecordsetClone.NoMatch Then
            '-- Record found, sync the form to this record
            Me.Bookmark = Me.RecordsetClone.Bookmark
        Else
            '--- Record NOT found, add a new record
            DoCmd.RunCommand acCmdRecordsGoToNew
            Me.Custid = Me.OpenArgs
        End If
    Else
    '-- Nothing passed, just open on the 1st record
    End If
    End Sub

  4. #4
    nkenney is offline Advanced Beginner
    Windows 2K Access 2007
    Join Date
    Mar 2009
    Posts
    40

    Thank you!

    Thank you for your help. It worked wonderfully!

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great! Glad I could help.

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

Similar Threads

  1. OpenForm Action and Arguments
    By nkenney in forum Forms
    Replies: 9
    Last Post: 04-05-2009, 09:33 AM
  2. In a field on a Form, on click open another form
    By jackieagra in forum Programming
    Replies: 1
    Last Post: 03-20-2008, 09:44 AM
  3. Form will not open
    By dserbanescu in forum Forms
    Replies: 0
    Last Post: 01-09-2008, 09:48 AM
  4. Using combo box to open another form
    By ladyairj23 in forum Forms
    Replies: 0
    Last Post: 06-02-2006, 07:03 AM
  5. Open form in another database
    By Karyn-2000 in forum Forms
    Replies: 0
    Last Post: 04-19-2006, 10:17 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