Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ac

Status
Not open for further replies.

ag90fox

IS-IT--Management
Mar 14, 2002
17
0
0
US
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?

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.


Thanks,

Joe
 
You may try this instead:
Private Sub cmdResub_Click()
DoCmd.RunCommand acCmdSelectRecord
DoCmd.RunCommand acCmdCopy
DoCmd.RunCommand [!]acCmdPasteAppend[/!]
Me!HoursBilled = 0
Me!AssignedDate = Date()
End sub


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I did try that, same result, except the record navigation at the bottom of the form shows the new record, but the data on the screen is that exact same as the old record until I manually navigate one record back, then one forward to the same point at which time the data looks like it should.
 
Have you tried testing for an error on this line. Within this routine I would add the error checking "stuff"
Before running this code I would put a breakpoint on the "resume next" line at the bottom of the routine. If there is an error, the error description should help a lot.
ps: sorry the "RunCommand" didn't help.
Code:
Private Sub cmdResub_Click()
on error goto ErrorRoutine
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()

exit sub
ErrorRoutine:
  debug.print err, err.description
[COLOR=white #663333]  resume next               [/color]
End sub
 
Thanks for the idea Vic. Unfortunately, there appears to be no error as adding that code did not change the execution of the code. It pasted the information into the new record and then stopped executing the code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top