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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"can't go to specified record" error in VBA 1

Status
Not open for further replies.

thepope77

Technical User
Jul 1, 2003
26
US
I have a command button that goes to a new record when clicked. However, I have some validation on a text box that ensures that the user enters a certain number. If this condition is not met, a message box is thrown up and the user can't advance until the condition is met. It is on this step that I get the error "can't go to specified record". I think it is the procedure behind the command button that is the culprit. Can I put something in the error handling code of the button that will control this?

Here is the code for the button:

Private Sub cmdTestNextReel_Click()
On Err GoTo Err_cmdTestNextReel_Click

DoCmd.GoToRecord , , acNewRec
Me.txtJDEdwardsNumber.SetFocus

Exit_cmdTestNextReel_Click:
Exit Sub

Err_cmdTestNextReel_Click:
MsgBox "Click OK to continue.", vbInformation, "Transfer Reels"
Resume Exit_cmdTestNextReel_Click

End Sub

txtJDEdwardsNumber is the control with the validation code.

Thanks so much.

Daniel Pope
 
Maybe this isn't the best method, but put "Msgbox err.number" and record the error number when this happens. Then close it out, go back in into design view and go in the error handler, cut out the msgbox err.number line. THEN put "If Err.number = (--insert-myRecordedNumber-here--) Then Resume Exit_cmdTestNextReel_Click"


That will get you around the problem.
 
try inserting your validation code in the command button On Click instead using a nested if.

Private Sub cmdTestNextReel_Click()
On Err GoTo Err_cmdTestNextReel_Click

If Me.YourTextBoxName <> YourNumberGoesHere Then

msgbox(&quot;User cannot advance.&quot;)
Exit Sub

Else

DoCmd.GoToRecord , , acNewRec
Me.txtJDEdwardsNumber.SetFocus

End If

Exit_cmdTestNextReel_Click:
Exit Sub

Err_cmdTestNextReel_Click:
MsgBox &quot;Click OK to continue.&quot;, vbInformation, &quot;Transfer Reels&quot;
Resume Exit_cmdTestNextReel_Click

End Sub

hope this helps you.
 
Thanks cghoga. That worked out just fine. I appreciate the help.

Daniel Pope
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top