Results 1 to 8 of 8
  1. #1
    Computer202 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Lincolnshire, ENGLAND
    Posts
    25

    Post Copy and Paste Row (vb)

    Hi

    As much as I know about access doesn't help me when it comes to anything in VB. Excel wise this wouldn't be a problem but slightly stuck



    Right I have 2 forms, FrmPS2 and FrmBundle

    When Browsing FrmPS2 I need to be able to select a row (I have no primary Key) and then click a button which simply copies and pastes that into FrmBundle. Is that possible?

    I understand this is through the use of modules and I am unsure how to use these, in other words how do you get a module on a toolbar?

    Thanks

    Would appreciate any help

  2. #2
    Computer202 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Lincolnshire, ENGLAND
    Posts
    25
    Anyone? It would really save a lot of time

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Let me get you straight you have a fOrm you want to select a row and the same gets copied onto another form.


    I have two forms

    Main:{Details,de,da}
    Main21:{Details,de,da}


    now I want to copy Main:{Details,de,da} to Main21:{Details,de,da} by clicking on a button on form Main:
    Create a CommandButton and in its onclick event type the following:

    Private Sub Command12_Click()
    Dim frm As Form
    Dim rs As DAO.Recordset

    'Save any edits.
    If Me.Dirty Then Me.Dirty = False
    'Check there is a record to copy.
    If Me.NewRecord Then
    MsgBox "Select a record to copy"
    Else
    'Open the other form if needed, and save any edits.
    If Not CurrentProject.AllForms("Main21").IsLoaded Then
    DoCmd.OpenForm "Main21"
    End If
    Set frm = Forms("Main21")
    If frm.Dirty Then frm.Dirty = False

    'Add the new record to the other form's clone set.
    Set rs = frm.RecordsetClone
    rs.AddNew
    'Substitute your field names on the following lines.
    rs!Details = Me.Details
    rs!de = Me.de
    rs!da = Me.da
    'etc for other fields
    rs.Update

    'Show this record in the other form.
    frm.Bookmark = rs.LastModified
    frm.SetFocus
    End If

    Set rs = Nothing
    Set frm = Nothing
    End Sub

    Note: Fields name in both the forms need not be same.

    if this solves your problem please mark this thread solved.

  4. #4
    Computer202 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Lincolnshire, ENGLAND
    Posts
    25
    This is exactly what was needed but no luck?

    I opened the form "Main" and added a button, Changed the code for the relevant fields and Form name, When I opened the form, I selected the row I wanted, Clicked the button and all it did was open the other table, it didn't copy any data?????

    Cheers

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931

    Copy/Paste

    I really don't get you you say table it is suppose to open another form.

    Now I am attaching the mdb file for your reference. Unfortunately I am in my office and here we use Open source and only one com has Ms office 2000 Professional.

  6. #6
    Computer202 is offline Novice
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    Lincolnshire, ENGLAND
    Posts
    25

    Thumbs up

    Thanks a lot that is exactly what I wanted...

    I tried you database and that worked so I re-checked and doubled checked mine, In the end I decided to rename my button and command to Command10 (same as yours) that way it couldn't go wrong... IT WORKED...

    Thanks a lot!


  7. #7
    Caroline is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2014
    Posts
    2
    Hi Maximus,
    Your Code works great! I have been searching thru the Web for 3 days for solution and tried and tried and tried but failed... until I found yours! Really appreciate!

  8. #8
    Caroline is offline Novice
    Windows XP Access 2007
    Join Date
    Mar 2014
    Posts
    2
    Hi Maximus,
    Your Code works great! I have been searching thru the Web for 3 days for solution and tried and tried and tried but failed... until I found yours! Really appreciate!

    If possible, I really need your little advise on following part:

    'Open the other form if needed, and save any edits.
    If Not CurrentProject.AllForms("SubformPO_DETAILS").IsLoa ded Then
    DoCmd.OpenForm "SubformPO_DETAILS"
    End If
    Set frm = Forms("SubformPO_DETAILS")

    With reference to your sample : Main = My "Item Finder" Main2 = My "SubformPO_Details"
    Both forms are the Subforms (by Tab Control) for My "FormPURCHASE_ORDER"

    The Command Button will Paste the record from "Item Finder" to "SubformPO_Details" but not to the "SubformPO_Details" that reside in the Tab Ctrl of "FormPURCHASE_ORDER"
    Is there a way to paste the records directly to the FormPURCHASE_ORDER -> Tab Ctrl -> SubformPO_DETAILS?
    And there is no necessary to OpenForm "SubformPO_DETAILS"...

    Thanks!

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

Similar Threads

  1. Replies: 2
    Last Post: 06-06-2011, 04:18 PM
  2. Replies: 2
    Last Post: 03-04-2010, 02:04 PM
  3. Replies: 5
    Last Post: 12-10-2009, 10:33 PM
  4. Replies: 0
    Last Post: 10-15-2009, 02:08 PM
  5. Copy a record
    By RHall in forum Programming
    Replies: 2
    Last Post: 02-23-2006, 07:40 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