Question : How to Stop Procedure Running after Message Box Displayed

How do I stop a procedure from running when an error has occurred and a message box displayed?

I have written an export records procedure.  If the records are to be exported to a database that is not in a trusted location I would like the procedure to stop completely (i.e. not export the records).  

At present, when the security notice is displayed and the cancel button is pressed, a message box displays informing the user that they must add that database name and directory path to the "trusted locations" of their database.  I then want the procedure to halt completely but at present when the "OKAY" button is pressed the records are still exported.

Any help would be very much appreciated.

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
Private Sub CmdExportRecords_Click()

On Error GoTo cmdTrustedLocation_Err

Me.FileList.SetFocus

DoCmd.Hourglass True
'Turns off the Access warning messages
DoCmd.SetWarnings False

DoCmd.OpenQuery "qryExportLatestStudentRecords"
DoCmd.OpenQuery "qryExportLatestUniversityApplications"

DoCmd.TransferDatabase acExport, "Microsoft Access", _
Me.FileList, _
acTable, "tblExportLatestStudentRecords", "tblExportedLatestStudentRecords"

DoCmd.TransferDatabase acExport, "Microsoft Access", _
Me.FileList, _
acTable, "tblExportLatestUniversityApplications", "tblExportedLatestUniversityApplications"

MsgBox ("Records Copied and Exported: " & DCount("ID", "tblExportLatestStudentRecords")), vbInformation, "PFL Export Student Records"
DoCmd.Hourglass False
'Turns the Access warning messages back on
DoCmd.SetWarnings True

cmdTrustedLocation_Err:

DoCmd.Hourglass False
'Turns the Access warning messages back on
DoCmd.SetWarnings True
    If Err.Number = 2001 Then
        Msg = "You clicked the CANCEL Button when a security notice was displayed." & vbCrLf & _
"The Security Notice message was displayed because you have not added the database directory name to the TRUSTED LOCATIONS area." & vbCrLf & _
"Please add the database name and try the export procedure again." 
        MsgBox Msg, vbExclamation + vbOKOnly, "Export Procedure - Security Warning Notice"
    End If

End Sub

Answer : How to Stop Procedure Running after Message Box Displayed

Yes ... is the transfer *really* occurring ?

It looks like the trusted info is here for Access 2007, similar for A2010.

it looks as if there is a Registry setting:
[HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\A ccess\Security\TrustedLocations]

Not on my A2010 system now, but I have seen that key ... and there is a list of TL's that have been added - if any.  So, you would need to check this Reg key ... and see if 1) the key exists, 2) if so, is the target folder listed, 3) if not, the do not execute the transfer.

There are API calls to get Reg info ...

mx
Random Solutions  
 
programming4us programming4us