Results 1 to 7 of 7
  1. #1
    John V is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    43

    Passing values from main form to popup form

    I know this has been discussed here a million times before but I am not finding an answer to my problem (at least not one my little brain can understand).

    I have a main form for entering Employer Information (frmEmployers) and this form has a command button on it for opening a form to enter Retirement Plan information (frmRRSP).

    Originally the Employer Form did not have a textbox for displaying the EmployerID (PK) but I was forced to add one (txtEmployerID) (Visible=No) when I used the wizard for adding the command button.

    The Employer form has tblEmployer as its recordsource and the RRSP form has tblRRSP as its recordsource.

    The RRSP form that gets opened with the command button has Fields for RRSP Rate and the Dates the RRSP Rate is in Effect. It does not have a textbox for displaying the EmployerFK from the main form. Nor does it have a textbox for displaying the RatdeID (PK from the RRSP table).



    The wizard asked me to choose which fields contain matching data to use for lookup, I chose txtEmployerID from frmEmployers and EmployerFK from frmRRSP and linked them with the "<->" button in the wizard.

    I would like to have EmployerID (PK field from the Employer Table) be transferred to the EmployerFK field of the RRSP Table. This isn't happening. Why not?

    I have tried adding a textbox to the RRSP form and setting its controlsource as EmployerFK. This did not work. I have setup a relationship between the Employer Table (EmployerID field) and the RRSP Table (EmployerFK field).

    Do I need to use OpenArgs? If I do, how? I can't get the syntax quite right.

    TIA
    John V

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Is your popup form bound? Here is an example:
    Forms![PopupForm]![SomeField] = Forms![MainForm].[SomeField]
    Me.Dirty = False
    HTH

  3. #3
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Hello John
    Try this code

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "NameForm"
    stLinkCriteria = "[NameID]=" & "'" & Me![NameID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

  4. #4
    John V is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    43
    I was hoping that would be taken care of when "linking" EmployerID and EmployerFK with the wizard. Apparently not.

    John V

  5. #5
    John V is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2014
    Posts
    43
    I tried it and it didn't work. Not sure that I am replacing "NameID" and "NameForm with the right things though, and I am assuming I am supposed to.

    Here is what I did:

    I replaced "NameForm" with the name of the popup form (frmRRSP) and the first "NameID" with the field name I am trying to pass the value to (EmployerFK) and the second "NameID with the textbox name from the main form (EmployerID) I am trying to pass the value from.

    I put this code in the Click event of the command button that opens the popup form. So my code looks like this:

    Private Sub EditRRSP_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmRRSP"
    stLinkCriteria = "[EmployerFK]=" & "'" & Me![EmployerID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

    End Sub

    I put this code in the Click event of the command button that opens the popup form.

  6. #6
    azhar2006's Avatar
    azhar2006 is offline Expert
    Windows 7 32bit Access 2007
    Join Date
    Mar 2012
    Posts
    528
    Put it up for a field name in the (frmEmployers)
    And double-click the event

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Is EmployerID text data type? Do you want to open the form to an existing record? The suggested code should accomplish that.

    If you want to open the form to a new record and populate the EmployerFK field with EmployerID, review https://www.accessforums.net/forms/f...les-45450.html
    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.

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

Similar Threads

  1. Linking a popup form to the main form
    By dvgef2 in forum Forms
    Replies: 9
    Last Post: 03-25-2013, 04:57 PM
  2. Replies: 11
    Last Post: 01-10-2013, 06:23 PM
  3. Replies: 1
    Last Post: 02-29-2012, 09:38 AM
  4. Replies: 10
    Last Post: 09-27-2010, 08:06 PM
  5. Replies: 3
    Last Post: 06-02-2009, 09:51 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