Checking for a database password

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm looping through a list of files to compress one at a time. I'm getting
an error when a database has a password. I need to skip over that one, but
I'm having trouble trapping the error. I have an OnERR statement, but it
throws a Run-time error: 3031. Any suggestions?

Here's a snippet of the code:
Private Sub cmdCompact_Click()
On Error GoTo Err_Log_Error
Dim oldFullPath As String
Dim newFullPath As String
DAO.DBEngine.CompactDatabase newFullPath, oldFullPath
Err_Log_Error:
(some script)

Thanks for any ideas.
 
Catch error 3031 and continue?

(To put it another way.... what is your (some script)?... and where's the
loop?)
 
How do I 'catch' errors in VBA? I have the 'On Error GoTo' line at the top.
I know about using the Select Case statement to handle specific errors, but
it's not catching them. I'm getting the End/Debug MsgBox before it 'throws'
the error. How do I catch it? The loop isn't necessary.
 
Joshua Schairbaum said:
How do I 'catch' errors in VBA? I have the 'On Error GoTo' line at the
top.
I know about using the Select Case statement to handle specific errors,
but
it's not catching them. I'm getting the End/Debug MsgBox before it
'throws'
the error. How do I catch it? The loop isn't necessary.



Although you have not shown the complete sub, it sounds like you do
understand how to include error-handling in your code. If not, I have given
a sample below.
It sounds to me like you should check your error-handling options for the
project. While looking at the vba code, select Tools>Options>General tab
and check it has not been set to "break on all errors". If so, change it to
"break on un-handled errors"

Example:
Private Sub cmdTest_Click()

On Error GoTo Err_Handler

DoCmd.OpenForm "frmWhatever"

Exit_Handler:

Exit Sub

Err_Handler:

Select Case Err.Number

Case 2102
' The form does not exist
MsgBox "Someone has deleted the form"
Resume Next

Case Else
MsgBox Err.Description, vbExclamation, _
"Error No: " & Err.Number
Resume Exit_Handler

End Select

End Sub
 
Something like this... at the top of the sub/function have...

On Error GoTo ErrHandler 'which tells it to go to another line when
there's an error

....and at the end of the sub/function add in this...

ExitPoint:
Exit Sub/Function

ErrHandler:
If Err.Number = 3031 Then
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume ExitPoint
End If
End Sub/Function

So if an error (i.e. any error) is caught then code skips to the ErrHandler
line. That checks what the error number is... if it is 3031 then the resume
next tells the code just to go back to wherever it went wrong and carry
on... and if it's not 3031 then display an error message and then go to
ExitPoint so that the sub/function finishes correctly.
 
Great. Thanks for the help.

Rob Oldfield said:
Something like this... at the top of the sub/function have...

On Error GoTo ErrHandler 'which tells it to go to another line when
there's an error

....and at the end of the sub/function add in this...

ExitPoint:
Exit Sub/Function

ErrHandler:
If Err.Number = 3031 Then
Resume Next
Else
MsgBox Err.Description, vbExclamation, "Error " & Err.Number
Resume ExitPoint
End If
End Sub/Function

So if an error (i.e. any error) is caught then code skips to the ErrHandler
line. That checks what the error number is... if it is 3031 then the resume
next tells the code just to go back to wherever it went wrong and carry
on... and if it's not 3031 then display an error message and then go to
ExitPoint so that the sub/function finishes correctly.
 

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

Back
Top