Results 1 to 9 of 9
  1. #1
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97

    How to use openArgs to pass a value to new records on a different form

    I have a primary form (primary key : ID) with a button. The button opens a secondary form showing all records linked to the primary form via the primary key. I would like to fill the ID field in the secondary form by passing "ID" value from the primary form.
    I have successfully implemented the openArgs function by passing "ID" value to the first linked record, but I cannot pass "ID" to NEWLY CREATED linked records created on the secondary form..
    Any suggestion ?
    If it works I would be happy to lock the "ID" control on the secondary form so that it cannot accidentally changed.


    Thanks,

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    If your first form is still open you can drag that ID to the new form, if the first form is not going to be open when you have the second form over what I would do is have an unbound text box on the secondary form that has the ID field (copy it from your first form when you open the new form), then apply that ID to all new records that are generated on the new form.

  3. #3
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    Quote Originally Posted by focosi View Post
    I have a primary form (primary key : ID) with a button. The button opens a secondary form showing all records linked to the primary form via the primary key. I would like to fill the ID field in the secondary form by passing "ID" value from the primary form.
    I have successfully implemented the openArgs function by passing "ID" value to the first linked record, but I cannot pass "ID" to NEWLY CREATED linked records created on the secondary form..
    Any suggestion ?
    If it works I would be happy to lock the "ID" control on the secondary form so that it cannot accidentally changed.
    Thanks,
    Is this what you are looking for?
    https://www.accessforums.net/forms/s...rds-15377.html

    check the last post and there is a link to site that i got it from.

  4. #4
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    @rpeare : what do you mean by "drag" ? At the top of my head drag&drop is not supported in Access forms.. or maybe I disabled some function??? Anyway, this is not a solution to me. I want to pass the value and lock the control every time I create a new linked record, I don't want to copy it manually and leave the field prone to accidental changes made by users. I have succesfully implemented passing the argument from the primary to the secondary form with the following code :

    on the primary form :

    Private Sub Donatori_Click()
    On Error GoTo Err_Donatori_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Dati donatori"
    stLinkCriteria = "[ID]=" & Me![ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.ID
    Exit_Donatori_Click:
    Exit Sub
    Err_Donatori_Click:
    MsgBox err.Description
    Resume Exit_Donatori_Click
    End Sub


    on the secondary form :

    Private Sub Form_Load()
    Dim strOpenArgs() As String
    If Not IsNull(Me.OpenArgs) Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.ID = strOpenArgs(0)
    End If
    End Sub

    What I need is to pass the argument when I create a new record (still linked to same ID in the primary form) on the secondary form.. Any idea ?

    @desibabu90 : maybe I'm wrong, but your video didn't help me.....

  5. #5
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    Quote Originally Posted by focosi View Post
    @rpeare : what do you mean by "drag" ? At the top of my head drag&drop is not supported in Access forms.. or maybe I disabled some function??? Anyway, this is not a solution to me. I want to pass the value and lock the control every time I create a new linked record, I don't want to copy it manually and leave the field prone to accidental changes made by users. I have succesfully implemented passing the argument from the primary to the secondary form with the following code :

    on the primary form :

    Private Sub Donatori_Click()
    On Error GoTo Err_Donatori_Click
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "Dati donatori"
    stLinkCriteria = "[ID]=" & Me![ID]
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.ID
    Exit_Donatori_Click:
    Exit Sub
    Err_Donatori_Click:
    MsgBox err.Description
    Resume Exit_Donatori_Click
    End Sub


    on the secondary form :

    Private Sub Form_Load()
    Dim strOpenArgs() As String
    If Not IsNull(Me.OpenArgs) Then
    strOpenArgs = Split(Me.OpenArgs, ";")
    Me.ID = strOpenArgs(0)
    End If
    End Sub

    What I need is to pass the argument when I create a new record (still linked to same ID in the primary form) on the secondary form.. Any idea ?

    @desibabu90 : maybe I'm wrong, but your video didn't help me.....
    i wasnt talking about the video. i was talking about this webpage:

    http://bytes.com/topic/access/answer...ate-new-record

    look at the comments section by MMcCarthy.

  6. #6
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    Quote Originally Posted by desibabu90 View Post
    i wasnt talking about the video. i was talking about this webpage:

    http://bytes.com/topic/access/answer...ate-new-record

    look at the comments section by MMcCarthy.
    got the point, but this doesn't solve my troubles.... Maybe I should I use a custom button+VBA to create a new record instead of the default starred button at the bottom of the form window ?
    Thx

  7. #7
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    im fairly new to access so i am not sure..i just thought that the solution I posted was what u were looking for.. can you post your database here so maybe someone can look at it?

  8. #8
    focosi is offline Advanced Beginner
    Windows XP Access 2010 32bit
    Join Date
    Jul 2011
    Posts
    97
    I actually fixed this by myself since the solution was simpler than I thought.
    I just put in the AfterUpdate event of my form (not the control) ...

    Me.ID.DefaultValue = """" & Me.ID.Value & """"

    ...to pass the ID value from the current record to all newly created records linked by ID to the primary form.
    Thanks for help anyway!

  9. #9
    desibabu90 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jun 2011
    Posts
    39
    oh okay.. glad it worked out!

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

Similar Threads

  1. Open a second form using the OpenArgs
    By blueraincoat in forum Forms
    Replies: 6
    Last Post: 06-02-2011, 06:19 AM
  2. Opening a form with openargs and things
    By mwabbe in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:01 AM
  3. One Form, Multiple records
    By andwhy81 in forum Forms
    Replies: 3
    Last Post: 09-21-2010, 12:12 PM
  4. Add Multiple Records on One Form
    By William McKinley in forum Forms
    Replies: 7
    Last Post: 08-18-2010, 09:31 AM
  5. Replies: 0
    Last Post: 03-19-2006, 11:52 PM

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