Returns to calling Sub before executing all of the code?

M

mrsdee

I have a Sub that renumbers records to allow for record insertion
anywhere in the table. For some reason the code returns to the
returning procedure after executing the LOC DoCmd.RunSQL(strSQL). I
have tried moving the last LOC above the DoCmd stmts and it returns to
the caller without executing any of the DoCmd stmts.

Any ideas why this may be happening?

Public Sub reNumber()
Dim newCtrlNum As Integer, curRecCtrlNum As Integer, frm As Form,
strSQL As String

'save current control number prior to renumbering-do renumbering prior
to assignment
'of number to new rec to prevent incidence of duplicate ctrl nums
Set frm = Forms![Update Product Area Checklist]
curRecCtrlNum = frm![txtCtrlNbr]

strSQL = "UPDATE[Product Checklist] SET [Control Number] = [Control
Number] + 1 WHERE [Control Number] >= " & curRecCtrlNum

DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

'assign number to new item
Me.txtCtrlNumber.Value = curRecCtrlNum

End Sub

Thanks!
 
J

Jeff Boyce

Disregard the "you can't do this" response. It is either SPAM or something
worse. Follow the link at your own peril!

The person posting the response has used several different aliases, and is
now representing him/herself as an MVP.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
M

mrsdee

Thanks for the heads up! But do you happen to know the cause of my
problem?
Jeff said:
Disregard the "you can't do this" response. It is either SPAM or something
worse. Follow the link at your own peril!

The person posting the response has used several different aliases, and is
now representing him/herself as an MVP.

Regards

Jeff Boyce
Microsoft Office/Access MVP

mrsdee said:
I have a Sub that renumbers records to allow for record insertion
anywhere in the table. For some reason the code returns to the
returning procedure after executing the LOC DoCmd.RunSQL(strSQL). I
have tried moving the last LOC above the DoCmd stmts and it returns to
the caller without executing any of the DoCmd stmts.

Any ideas why this may be happening?

Public Sub reNumber()
Dim newCtrlNum As Integer, curRecCtrlNum As Integer, frm As Form,
strSQL As String

'save current control number prior to renumbering-do renumbering prior
to assignment
'of number to new rec to prevent incidence of duplicate ctrl nums
Set frm = Forms![Update Product Area Checklist]
curRecCtrlNum = frm![txtCtrlNbr]

strSQL = "UPDATE[Product Checklist] SET [Control Number] = [Control
Number] + 1 WHERE [Control Number] >= " & curRecCtrlNum

DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

'assign number to new item
Me.txtCtrlNumber.Value = curRecCtrlNum

End Sub

Thanks!
 
M

mrsdee

Thanks for the heads up! But do you happen to know the cause of my
problem?
Jeff said:
Disregard the "you can't do this" response. It is either SPAM or something
worse. Follow the link at your own peril!

The person posting the response has used several different aliases, and is
now representing him/herself as an MVP.

Regards

Jeff Boyce
Microsoft Office/Access MVP

mrsdee said:
I have a Sub that renumbers records to allow for record insertion
anywhere in the table. For some reason the code returns to the
returning procedure after executing the LOC DoCmd.RunSQL(strSQL). I
have tried moving the last LOC above the DoCmd stmts and it returns to
the caller without executing any of the DoCmd stmts.

Any ideas why this may be happening?

Public Sub reNumber()
Dim newCtrlNum As Integer, curRecCtrlNum As Integer, frm As Form,
strSQL As String

'save current control number prior to renumbering-do renumbering prior
to assignment
'of number to new rec to prevent incidence of duplicate ctrl nums
Set frm = Forms![Update Product Area Checklist]
curRecCtrlNum = frm![txtCtrlNbr]

strSQL = "UPDATE[Product Checklist] SET [Control Number] = [Control
Number] + 1 WHERE [Control Number] >= " & curRecCtrlNum

DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

'assign number to new item
Me.txtCtrlNumber.Value = curRecCtrlNum

End Sub

Thanks!
 
M

mrsdee

And the answer is.... the field that I was attempting to update was not
updateable. It was AutoNumbered. Thanks anyway!
mrsdee said:
Thanks for the heads up! But do you happen to know the cause of my
problem?
Jeff said:
Disregard the "you can't do this" response. It is either SPAM or something
worse. Follow the link at your own peril!

The person posting the response has used several different aliases, and is
now representing him/herself as an MVP.

Regards

Jeff Boyce
Microsoft Office/Access MVP

mrsdee said:
I have a Sub that renumbers records to allow for record insertion
anywhere in the table. For some reason the code returns to the
returning procedure after executing the LOC DoCmd.RunSQL(strSQL). I
have tried moving the last LOC above the DoCmd stmts and it returns to
the caller without executing any of the DoCmd stmts.

Any ideas why this may be happening?

Public Sub reNumber()
Dim newCtrlNum As Integer, curRecCtrlNum As Integer, frm As Form,
strSQL As String

'save current control number prior to renumbering-do renumbering prior
to assignment
'of number to new rec to prevent incidence of duplicate ctrl nums
Set frm = Forms![Update Product Area Checklist]
curRecCtrlNum = frm![txtCtrlNbr]

strSQL = "UPDATE[Product Checklist] SET [Control Number] = [Control
Number] + 1 WHERE [Control Number] >= " & curRecCtrlNum

DoCmd.SetWarnings False
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings True

'assign number to new item
Me.txtCtrlNumber.Value = curRecCtrlNum

End Sub

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top