Results 1 to 5 of 5
  1. #1
    psunilve is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2013
    Posts
    4

    Copy From Command Button (Acc2007 form)

    Hello. Just a heads up I'm new to this forum and a novice in Access (in particular VBA) so i apologize if I don't sound techy. I need help on a code. I created a form that contains details of requests processed. There will be situations where 2-3 records will be created where 50% of the data are the same. I created a command button that will copy details of the current record to a new one. However there are fields that I want blank because these will contain different information. I used the control button wizard and converted it to a vba code. It does work however it copies everything. What I want to happen basically is when i click on the button it copies the current record but clears out info on certain fields and I will just manually update the info in those fields and save it.

    Below is the code I'm using:


    '------------------------------------------------------------
    ' CopyFrom_Click
    '
    '------------------------------------------------------------
    Private Sub CopyFrom_Click()
    On Error GoTo CopyFrom_Click_Err
    On Error Resume Next
    DoCmd.RunCommand acCmdSelectRecord
    If (MacroError = 0) Then
    DoCmd.RunCommand acCmdCopy
    End If
    If (MacroError = 0) Then
    DoCmd.RunCommand acCmdRecordsGoToNew
    End If
    If (MacroError = 0) Then
    DoCmd.RunCommand acCmdSelectRecord
    End If
    If (MacroError = 0) Then


    DoCmd.RunCommand acCmdPaste
    End If
    If (MacroError <> 0) Then
    Beep
    MsgBox MacroError.Description, vbOKOnly, ""
    End If

    CopyFrom_Click_Exit:
    Exit Sub
    CopyFrom_Click_Err:
    MsgBox Error$
    Resume CopyFrom_Click_Exit
    End Sub

    ==================================
    Any help will be greatly appreciated.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,822
    After the copy/paste set specific fields to null.

    Me!fieldname = Null
    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.

  3. #3
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    And since you're no longer using a Macro, do yourself a favor and get rid of all the MacroError code. It's now useless, takes up space and makes it hard to read/follow code. Doing that and following June7's suggestion:

    Code:
    Private Sub CopyFrom_Click()
    
    On Error GoTo CopyFrom_Click_Err
    
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.RunCommand acCmdRecordsGoToNew
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdPaste
    
    Me.Field1 = Null
    Me.Field2 = Null
    
    CopyFrom_Click_Exit:
    Exit Sub
    
    CopyFrom_Click_Err:
    MsgBox Error$
    Resume CopyFrom_Click_Exit
    
    End Sub

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  4. #4
    psunilve is offline Novice
    Windows Vista Access 2007
    Join Date
    Apr 2013
    Posts
    4
    Thanks June7!!!! It worked.

    Linq, did as you suggested. Cheers for that!

    You guys are awesome!!!

    P.S.
    I may have to post another question but i think i will do that after i have exhausted all my energy to make it work.

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    Glad we could help!

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Copy button on a form
    By MikeAllen in forum Forms
    Replies: 11
    Last Post: 08-29-2012, 06:20 AM
  2. Replies: 2
    Last Post: 03-07-2012, 08:39 AM
  3. Replies: 5
    Last Post: 02-21-2012, 07:33 AM
  4. Use a command button to open a form
    By johnpaul in forum Forms
    Replies: 24
    Last Post: 09-23-2010, 12:29 PM
  5. Replies: 1
    Last Post: 07-27-2010, 02:27 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