Results 1 to 3 of 3
  1. #1
    jlgray0127 is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185

    VBA in Form to copy record

    Private Sub Command44_Click()
    For n = 1 To Forms!BuildMaster!RepeatTime
    DoCmd.OpenQuery "BuildMaster_CopyLine"
    Next

    Me.RepeatTime = 1
    Me.CopyLine = False

    DoCmd.Requery

    End Sub



    Looking for some help with my code above. It seems buggy.

    I'm not a VBA guy, but am learning. What I'm doing, is I have a build schedule form for our facility.
    When we receive new orders, at times, we can copy another order, and then update the fields where the info changes when we receive that info.

    I can run this and it works, but not always succcessfully. I have a check box on the line, and when checked, we can enter into a text box, [RepeatTime], the number of times to copy the line if we have more than one order, and then click a button which runs the below code.

    First issue, it only works, if [RepeatTime] is greater than 2. If I try to copy 1 line, it will not work.
    Second issue, it works a few times, but then stops. I have to remove:

    Me.RepeatTime = 1

    Me.CopyLine = False

    DoCmd.Requery

    and run the code again, and then put the above code back in, and it will work again, several times, then stop again.
    I'm not sure how to modify it to get it to work again. The lines I'm having to remove, put the user input values back to the default values and requerys the form, so it refreshes and shows the new lines. I feel these are pretty important to keep, and know there's a way to do it. Just struggling on what I'm missing... I know this is almost barbaric coding, so any help is greatly appreciated!

    Thank you!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    this seems to be fine, but why is there a
    Forms!BuildMaster!RepeatTime
    and
    Me.RepeatTime ?

    Are they the same control? If so, make them consistant.
    what is me.CopyLine?
    It seems to have no relevance.

  3. #3
    jlgray0127 is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Oct 2011
    Location
    Central Illinois
    Posts
    185
    The are the same thing.
    me.copyline is the check box. When true, the query appends the record to the scheduling table.
    I also updated it to Forms!BuildMaster!CopyLine

    I have the same results. It's stopped running again.
    I think I found the error.... I need to requery after I select the record (CopyLine) as it's not refreshing fast enough, when I run the query.
    I've done some tests just looking at the query, and after I check the box, and just click the next record, it will run fine and repeates.

    I added the below, and it hasn't failed yet and is copying only 1 record if that is what I chose. Thank you for your help!

    Private Sub CopyLine_AfterUpdate()
    Me.Recordset.MoveNext
    Me.Recordset.MovePrevious
    End Sub

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

Similar Threads

  1. Copy a record and open in form
    By klnlsu in forum Programming
    Replies: 5
    Last Post: 05-17-2017, 10:34 AM
  2. Copy Record button on form
    By banpreet in forum Forms
    Replies: 4
    Last Post: 12-15-2016, 04:44 PM
  3. Replies: 2
    Last Post: 09-17-2014, 04:55 PM
  4. Copy record into pop-up form
    By arothacker in forum Forms
    Replies: 5
    Last Post: 03-27-2014, 12:23 PM
  5. Replies: 3
    Last Post: 03-09-2013, 10:39 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