Results 1 to 5 of 5
  1. #1
    Molly152 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    5

    Passing value from one form to another


    Hello

    I am sure that this question has been asked many times, but I cannot seem to find an answer that works. I have two forms, Form1 looks at tblChristmasCard field called CN_ID. I have created a cmd button, which opens frmAddMeToTheList with stLinkCriteria, and I want the new record to be populated with CN_ID from Form1.

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmAddMeToTheList"
    stLinkCriteria = "[CN_ID] =" & "'" & Me![CN_ID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.GoToRecord , , acNewRec
    Form_frmFRONTSHEET.CN_ID = Form_frmAddMeToTheList.CN_ID

    Please could someone help and explain what I am doing wrong.

  2. #2
    jzwp11 is offline VIP
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Welcome to the forum.

    What is the data type of the CN_ID field? If it is numeric, then you must not enclose it in quotes.

    Additionally, your form reference is incorrect. You have to supply the ID from the current form (frmFRONTSHEET I assume) to the form that you open (frmAddMeToTheList). So frmFRONTSHEET has to be on the righthand side of the assignment statment. So assuming that CN_ID is numeric, the code would look like this

    Code:
    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmAddMeToTheList"
    stLinkCriteria = "[CN_ID] =" & Me![CN_ID] 
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.GoToRecord , , acNewRec
    Forms!frmAddMeToTheList.CN_ID=Forms!frmFRONTSHEET.CN_ID

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    There are several issues that could be changed but your issue is the wrong direction:
    DestinationObject = SourceObject
    ...is the correct syntax. You seem to have it backwards.

  4. #4
    Molly152 is offline Novice
    Windows XP Access 2007
    Join Date
    Nov 2010
    Posts
    5

    Passing value from one form to another

    Thank you - once I swapped things around it works.

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Great Molly! Thanks for posting back.

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

Similar Threads

  1. Replies: 2
    Last Post: 10-01-2010, 04:28 AM
  2. Replies: 10
    Last Post: 09-27-2010, 08:06 PM
  3. Form Help with passing records
    By mwabbe in forum Forms
    Replies: 6
    Last Post: 09-08-2010, 11:06 AM
  4. Passing a form name to a subroutine
    By trb5016 in forum Programming
    Replies: 0
    Last Post: 02-01-2010, 12:03 PM
  5. Passing a variable to a form
    By cjamps in forum Forms
    Replies: 0
    Last Post: 03-02-2009, 05:32 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