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

Error Handler doesn't trigger

Status
Not open for further replies.

HomeGrowth

Technical User
Aug 19, 2004
76
0
0
US
I have an On Error handling on Form_Load, basically, if the user has the write access, goto New record. Usually, if the user doesn't have the write access, it generate error code 2105. So I have the error handling by goto First record. But My problem is the Error Handler didn't trigger, instead, I got the error message "Run time error '2105'. You can't goto the specific record". So, why the error handler can't work? Thanks!


Private Sub Form_Load()

On Error GoTo Err_Form_Load_Click

DoCmd.GoToRecord , , acNewRec

Exit_Form_Load_Click:
Exit Sub

Err_Form_Load_Click:
If Err.Number = 2105 Then
DoCmd.GoToRecord , , acFirst
Resume Next
Else
MsgBox Err.Description
Resume Exit_Form_Load_Click
End If

End Sub
 
Have you tried stepping through the code?
 
How are ya HomeGrowth . . .

The code you've provided doesn't detect [blue]Write Access![/blue], the biggest problem here. I could be wrong, but, it appears, prior to opening the form your detecting [blue]Write Access[/blue], and opening the form approriately. I believe the problem lies here, and its this code we need to see!

[blue]Your Thoughts? . . .[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
I didn't have the code to detect Write Access. I was thinking if VBA gets the error message "Run time error '2105'. You can't goto the specific record", then the Error Handled would take you to the First record because the error '2105'.

Do I need to code Write Access? Can I program sonething if it can't go the specific record, then goto first record.

Thanks!
 
HomeGrowth said:
[blue]I didn't have the code to detect Write Access . . . [purple]Do I need to code Write Access?[/purple][/blue]
[blue]Well . . . if your not detecting it . . . how do you know?[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
HomeGrowth
Your code works for me in a very simple form, which is why I suggest you step through the code to see why it is not working for you.
 
TheAceMan1

I was thinking to use the trick of error handler which will generate the '2105' error which means the user has write access (can't goto new record), thus on the error handler, the error handler will trigger and go to the first record.

Remou

I have to step through using an account doesn't have write access. The error message "Run time error '2105'. You can't goto the specific record" showed up, then the Error Handled wasn't triggered. If the read only user, the form would looping (in hourglass)and the form never show. Do you have a good way to debug this.

Thanks

 
When I say step through, I mean by setting a breakpoint in the code (F9 will toggle a breakpoint) and then pressing F8 to run each line one by one. Is this what you tried?
 
Yes, I step through the code (it is short code), the error is stop at

DoCmd.GoToRecord , , acNewRec

with error message "Run time error '2105'. You can't goto the specific record"

I thought the error handler would trigger if err.number = 2150. It is kind of odd that the error handler don't triggered. maybe something wrong with the form.
 
It is odd. As I said, the code worked for me. How do you make the form read only? Is it by setting Allow Edits to false? Have you tried the same code on a new form?
 

On Error GoTo Err_Form_Load_Click

DoCmd.GoToRecord , , acNewRec

your code does not produce the error until after the code error handling section thus the error with the goto new record problem.

if you want to prevent users adding new data then set the additions property to no.

Ian Mayor (UK)
Program Error
Your lack of planning is not my emergency!
 
HomeGrowth . . .

Are you using [blue]Access Security?[/blue] . . . If not, how/where are you setting permissions before you open the form. Any code here would be a big help . . .

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Romou,

I used code in a different form, it works good.

ProgramError and TheAceMan1,

The database uses User Level Security. The users who doesn't have write access won't be able to add records. The user will encounter the error '2105', but I have the error handler take the user to First Record.

I think I may rebuild the form...


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top