Results 1 to 10 of 10

Thread: Paste command in Access form code exits subroutine. Don't make no sense!

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Paste command in Access form code exits subroutine. Don't make no sense!

    I've got a button on a form copies the current record into a new record, using "runcommand" in the the following sequence:

    1. select record
    2. copy record
    3. goto new record
    4. paste record

    That works fine. Next, within the the same sub I want to change a few of the fields on that form, but I've found that the sub quits executing the code right after the paste command. I don't know if its automatically exiting the subprocedure, but I need the subprocedure to continue so I can change the field values. Can someone recommend a way to do this? Does it make sense that it dumps out of this code after the paste instead of continuing with the rest of the code?

    Code:

    Private Sub cmdResub_Click()
    DoCmd.RunCommand acCmdSelectRecord
    DoCmd.RunCommand acCmdCopy
    DoCmd.GoToRecord , , acNewRec
    response = MsgBox("recordcreated", vbYesNo... used this to verify code runs to this point
    DoCmd.RunCommand acCmdPaste
    -----code stops running here-----
    response = MsgBox("recordpasted", vbYesNo, "verify")
    Me.HoursBilled = 0
    Me.AssignedDate = now()

    End sub


    The way I found this out is by using msgbox's as flags. The MSGBOX function on line 4 executes, but the MSGBOX on line 6 and anything after doesn't execute. I also included an error checking subroutine that returned no errors.


    Thanks,

    Joe

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    Put a break at the beginning of the event and step through to see what is actually happening.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    Not too sure how to do what you're asking. how do you put a break in? thanks!

    Joe

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    Are you running this in VB6 or in Access?

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    MS Access 2003. Its visual basic underlying a command button on a form.

  6. #6
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    added code tags for easier reading...
    VB Code:
    1. Private Sub cmdResub_Click()
    2.      DoCmd.RunCommand acCmdSelectRecord
    3.      DoCmd.RunCommand acCmdCopy
    4.      DoCmd.GoToRecord , , acNewRec
    5.      response = MsgBox("recordcreated", vbYesNo... used this To verify code runs To this point
    6.      DoCmd.RunCommand acCmdPaste
    7.      -----code stops running here-----
    8.      response = MsgBox("recordpasted", vbYesNo, "verify")
    9.      Me.HoursBilled = 0
    10.      Me.AssignedDate = Now()
    11.      
    12. End Sub
    to add a breakpoint just click the column next to the line.. a dot will appear and the line will get highlighted.
    then whe u run the code it will stop there... use F8 to step one line at a time
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    Tried that. highlighted the line in red with the dot to the left. saved the form, opened the form, pressed the comand button and the code ran through without pausing at all, of course without executing the code past the accmdpast line.

  8. #8
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    dont save/close.. highligh then run... closing it will erase breakpoints
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  9. #9

    Thread Starter
    New Member
    Join Date
    Apr 2006
    Posts
    5

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    Man, I can't win for losing! I went in, set the breakpoints, minimized the code window, went to form view, pressed the comman button and it still went all the way through the code to the paste event where it quits.

    I'm really not trying to make this difficult!)

  10. #10
    eltiT resU motsuC Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Paste command in Access form code exits subroutine. Don't make no sense!

    hmmm...

    I guess u will need to use another method..

    like using an INSERT query
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width