Results 1 to 10 of 10
  1. #1
    CrosScottish is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    5

    Copy value from one form to another

    I use the following code in a database I have to copy the course title text box from one form box to another form.

    Code:
    Private Sub CourseTitle_AfterUpdate()
    Dim cTitle As String
        cTitle = Me.CourseTitle.Column(0)
        DoCmd.OpenForm "frmCourseStudentRecord", acNormal, , _
        "strCourseTitle='" & cTitle & "'"
        DoCmd.Close acForm, Me.Name
    End Sub
    This works great but what I can't seem to solve and need some help with is rather than copy the course title to the other form I would like to copy the venue, which is in the same table, linked to this course title but not shown in the form. I would then automatically populate the frmCourse with this. The Row Source for the CourseTitle is a Query based on tblCourslist, which has the venue included in this table.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    does the starting form have a primary key or some other unique identifier in the data source that you can use to look up the value you want?

    If so you can use the dlookup function to find the value you want to pass to the new form.

  3. #3
    CrosScottish is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    5

    Primary key

    The first form simply searches the course title through a drop down box, but this is linked to the tblCoursetitle, which does have a primary key CourseID.

    How do i use the dlookup function in this case.

    Thanks for your help.

  4. #4
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    forms!newform!newformfieldname = dlookup("[Venue]", "tblCourseList", "[CourseID] = " & forms!currentform!currentformfieldname & ")

    where newform is the name of the form you're opening
    newformfieldname is the name of the field where you want to put the venue

    currentform is the form you're opening the new form from
    currentformfieldname is the name of the field that contains the classID

    this assumes of course your unique identifier on tblCourseList is named COURSEID and the venue is VENUE.

  5. #5
    CrosScottish is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    5
    How do I ammend my code to incorporate the above. Sorry, I am quite new to this.

  6. #6
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    There a number of ways to implement it. You could run the command in the ON OPEN event of your secondary form or in the ON CLICK event if your first form button that opens the second form.

  7. #7
    CrosScottish is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    5
    If I wanted to keep it as in the original code above on the AfterUpdate in my first form, where do I insert the code you have given me and what would I need to remove?

  8. #8
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Can you post a sample database?

  9. #9
    CrosScottish is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2011
    Posts
    5
    I seem to have solved it. Gone back to an old database I had and worked back with the code.

  10. #10
    alex_raju is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Jun 2011
    Posts
    56

    Copy value from one form to another

    hi,

    if i in u r way pls try it.

    double click on data source location of main form ( here SrchBarcode)
    destination location of subform or other form (here Forms![Invoice]![barcode])



    Private Sub srchBarcode_DblClick()
    dim BC as string
    BC = me![srchBarcode]
    Forms![Invoice]![barcode] = BC
    end Sub

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

Similar Threads

  1. copy from popup form to main form
    By alex_raju in forum Forms
    Replies: 2
    Last Post: 02-10-2012, 05:29 PM
  2. Replies: 1
    Last Post: 07-23-2011, 11:51 PM
  3. Replies: 3
    Last Post: 07-23-2011, 12:45 AM
  4. Copy from one form to another
    By Adam858 in forum Forms
    Replies: 3
    Last Post: 07-29-2010, 01:27 PM
  5. Replies: 0
    Last Post: 11-10-2008, 12:32 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